質問編集履歴

4

文言ミス

2020/01/12 03:18

投稿

kimukimu009
kimukimu009

スコア33

test CHANGED
File without changes
test CHANGED
@@ -120,7 +120,7 @@
120
120
 
121
121
  ・また、他のご回答者(m.ts10806様)の方から、今回の私が質問を行ったそもそもの理由(pyhton(selenium)で自動化ができない)
122
122
 
123
-  の部分にて、ご回答をいただきましたので、以下に、追記させていただきます。
123
+  の部分にて、ご回答をいただきました(具体的なソースなどがないと判断できない)ので、以下に、追記させていただきます。xpathのパターンを2パターン、記載いたします。
124
124
 
125
125
 
126
126
 

3

文言間違い

2020/01/12 03:18

投稿

kimukimu009
kimukimu009

スコア33

test CHANGED
File without changes
test CHANGED
@@ -76,6 +76,14 @@
76
76
 
77
77
 
78
78
 
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
79
87
  ■ここからが、最初の質問から、追記(編集)しているところ
80
88
 
81
89
 
@@ -304,7 +312,7 @@
304
312
 
305
313
 
306
314
 
307
- ■エラー内容(パターン2)
315
+ ■エラー内容(パターン2)
308
316
 
309
317
  ```
310
318
 

2

2つのパターンのxpachで試しましたので、エラーパターン1、エラーパターン2としました。

2020/01/12 03:15

投稿

kimukimu009
kimukimu009

スコア33

test CHANGED
File without changes
test CHANGED
@@ -238,7 +238,7 @@
238
238
 
239
239
 
240
240
 
241
- ■エラー内容
241
+ ■エラー内容1(パターン1)
242
242
 
243
243
  ```
244
244
 
@@ -304,7 +304,7 @@
304
304
 
305
305
 
306
306
 
307
- ■エラー内容
307
+ ■エラー内容1(パターン2)
308
308
 
309
309
  ```
310
310
 

1

「■ここからが、最初の質問から、追記(編集)しているところ」です。

2020/01/12 03:14

投稿

kimukimu009
kimukimu009

スコア33

test CHANGED
File without changes
test CHANGED
@@ -69,3 +69,275 @@
69
69
 
70
70
 
71
71
  そもそもHTMLファイルの中に、ラジオボタンの文言が存在しない。(デベロッパーツールで、ラジオボタンのxpathは存在しているにもかかわらず)から、押せないのではないかという仮説にたっています。
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ ■ここからが、最初の質問から、追記(編集)しているところ
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+ 上記の質問に対して、いくつかのご回答をいただきましたので、まずは、まとめます。
94
+
95
+
96
+
97
+ 【ご回答1】
98
+
99
+ ・maisumakun様から:「SPA(Single Page Application)」により、ほぼ完全に
100
+
101
+  JavaScriptで構築してしまって、HTMLには最低限のタグしかない、というような実装もありえる。
102
+
103
+
104
+
105
+  →その場合は、HTMLタグの中に、「その他」のような文言がでてこないことが
106
+
107
+   あり得るということです。
108
+
109
+
110
+
111
+ 【ご回答2】
112
+
113
+ ・また、他のご回答者(m.ts10806様)の方から、今回の私が質問を行ったそもそもの理由(pyhton(selenium)で自動化ができない)
114
+
115
+  のの部分にて、ご回答をいただきましたので、以下に、追記させていただきます。
116
+
117
+
118
+
119
+
120
+
121
+ ■HTMLファイルの中身(かなり複雑なので、抜粋して記載)
122
+
123
+
124
+
125
+ 具体的なソースファイル(ソースファイルを記載していますが、一部です。)
126
+
127
+ ```
128
+
129
+ <!doctype html>
130
+
131
+ <!--[if IE 8]><html data-19ax5a9jf="dingo" lang="ja-JP" class="a-no-js a-lt-ie10 a-lt-ie9 a-ie8"><![endif]--><!--[if IE 9]><html data-19ax5a9jf="dingo" lang="ja-JP" class="a-no-js a-lt-ie10 a-ie9"><![endif]--><!--[if !(IE 8)&!(IE 9)]><!--><html data-19ax5a9jf="dingo" lang="ja-JP" class="a-no-js"><!--<![endif]--><head><script>var aPageStart = (new Date()).getTime();</script><meta charset="utf-8"/>
132
+
133
+ <script type='text/javascript'>var ue_t0=ue_t0||+new Date();</script>
134
+
135
+
136
+
137
+ <div id="athena-widget-container"></div>
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+ <div id="sc-masthead" class="clearable">
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+ <!-- →→■■ここ!!■■「※ラジオボタンがあるコンテンツを読み込んでいると思われるjavascript -->
158
+
159
+ <script type="text/javascript">if(typeof uet == "function"){uet('ne');}</script></div><div id="sc-content-container">
160
+
161
+
162
+
163
+
164
+
165
+ <div id="ayb-app"></div>
166
+
167
+ </div><div id="sc-footer-container">
168
+
169
+
170
+
171
+ ```
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+ ■pythonファイル
182
+
183
+
184
+
185
+ ```
186
+
187
+ # seleniumを使う準備
188
+
189
+ from selenium import webdriver
190
+
191
+ from selenium.webdriver.chrome.options import Options
192
+
193
+
194
+
195
+ options = Options()
196
+
197
+ PROFILE_PATH = r'C:\Users\motoc\AppData\Local\Google\Chrome\User Data'
198
+
199
+ options.add_argument('--user-data-dir=' + PROFILE_PATH)
200
+
201
+ driver = webdriver.Chrome(options=options)
202
+
203
+
204
+
205
+ #その他の試し1
206
+
207
+
208
+
209
+ driver.get("https://sellercentral-japan.amazon.com/messaging/contact?orderID=250-4522981-2115804&marketplaceID=A1VC38T7YXB528")
210
+
211
+
212
+
213
+ driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div/div/div[2]/kat-box/div/kat-radiobutton[2]/div[2]/kat-label[1]').click()
214
+
215
+ ```
216
+
217
+
218
+
219
+
220
+
221
+ ■HTMLソース(デベロッパーツールで、検証→該当場所を探り、copy→xpathのフルパスコピー)
222
+
223
+ ```
224
+
225
+ <span class="kat-radiobutton-icon" role="radio" aria-details="31w2kk6hn8" aria-label="大型または重量商品の配送を調整する" tabindex="0" aria-checked="true"></span>
226
+
227
+ ```
228
+
229
+
230
+
231
+ ■XPATH
232
+
233
+ ```
234
+
235
+ /html/body/div[1]/div[2]/div/div/div/div[2]/kat-box/div/kat-radiobutton[2]/div[1]/span
236
+
237
+ ```
238
+
239
+
240
+
241
+ ■エラー内容
242
+
243
+ ```
244
+
245
+ DevTools listening on ws://127.0.0.1:56966/devtools/browser/85a7fa7d-467a-4f88-8fb3-c052f70a6a6a
246
+
247
+ Traceback (most recent call last):
248
+
249
+ File "C:\Users\motoc\OneDrive\デスクトップ\radio2.py", line 14, in <module>
250
+
251
+ driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div/div/div[2]/kat-box/div/kat-radiobutton[2]/div[1]/span').click()
252
+
253
+ File "C:\Users\motoc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
254
+
255
+ return self.find_element(by=By.XPATH, value=xpath)
256
+
257
+ File "C:\Users\motoc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
258
+
259
+ return self.execute(Command.FIND_ELEMENT, {
260
+
261
+ File "C:\Users\motoc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
262
+
263
+ self.error_handler.check_response(response)
264
+
265
+ File "C:\Users\motoc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
266
+
267
+ raise exception_class(message, screen, stacktrace)
268
+
269
+ selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[1]/div[2]/div/div/div/div[2]/kat-box/div/kat-radiobutton[2]/div[1]/span"}
270
+
271
+ (Session info: chrome=79.0.3945.117)
272
+
273
+
274
+
275
+ [10396:12376:0110/153344.524:ERROR:native_message_process_host.cc(344)] Error when writing to Native Messaging host: -101
276
+
277
+ ```
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+ ■HTMLソース(デベロッパーツールで、検証→該当場所を探り、copy→xpathのフルパスコピー)
288
+
289
+ ```
290
+
291
+ <kat-label class="text" for="b41lx6rqbq" text="大型または重量商品の配送を調整する"><label for="b41lx6rqbq"><span class="emphasis kat-label-hide"></span><span class="text">大型または重量商品の配送を調整する</span></label></kat-label>
292
+
293
+ ```
294
+
295
+
296
+
297
+ ■XPATH
298
+
299
+ ```
300
+
301
+ /html/body/div[1]/div[2]/div/div/div/div[2]/kat-box/div/kat-radiobutton[2]/div[2]/kat-label[1]
302
+
303
+ ```
304
+
305
+
306
+
307
+ ■エラー内容
308
+
309
+ ```
310
+
311
+ DevTools listening on ws://127.0.0.1:57041/devtools/browser/43a85349-40e9-4527-8ddc-7700f427adb8
312
+
313
+ Traceback (most recent call last):
314
+
315
+ File "C:\Users\motoc\OneDrive\デスクトップ\radio2.py", line 14, in <module>
316
+
317
+ driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div/div/div[2]/kat-box/div/kat-radiobutton[2]/div[2]/kat-label[1]').click()
318
+
319
+ File "C:\Users\motoc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
320
+
321
+ return self.find_element(by=By.XPATH, value=xpath)
322
+
323
+ File "C:\Users\motoc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
324
+
325
+ return self.execute(Command.FIND_ELEMENT, {
326
+
327
+ File "C:\Users\motoc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
328
+
329
+ self.error_handler.check_response(response)
330
+
331
+ File "C:\Users\motoc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
332
+
333
+ raise exception_class(message, screen, stacktrace)
334
+
335
+ selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[1]/div[2]/div/div/div/div[2]/kat-box/div/kat-radiobutton[2]/div[2]/kat-label[1]"}
336
+
337
+ (Session info: chrome=79.0.3945.117)
338
+
339
+
340
+
341
+ [6736:15044:0110/153810.848:ERROR:native_message_process_host.cc(344)] Error when writing to Native Messaging host: -101
342
+
343
+ ```