質問編集履歴

2

試したことに追記

2021/03/15 13:14

投稿

toshi_worldtrip
toshi_worldtrip

スコア3

test CHANGED
File without changes
test CHANGED
@@ -138,7 +138,7 @@
138
138
 
139
139
 
140
140
 
141
- iをだものをxpath指定することはできないのでょうか?
141
+ iを{i}で囲でみましたが、解決には至りませんでした。
142
142
 
143
143
 
144
144
 

1

エラー内容を詳細に記述

2021/03/15 13:14

投稿

toshi_worldtrip
toshi_worldtrip

スコア3

test CHANGED
File without changes
test CHANGED
@@ -20,9 +20,31 @@
20
20
 
21
21
  ```
22
22
 
23
- while(i<len(start_places)):
23
+ Traceback (most recent call last):
24
24
 
25
+ File "/xxx.py", line 32, in <module>
26
+
27
+ start_places[i] = driver.find_element_by_xpath("//*[@id='dep_list']/ul/li[i]")
28
+
29
+ File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
30
+
31
+ return self.find_element(by=By.XPATH, value=xpath)
32
+
33
+ File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element
34
+
35
+ return self.execute(Command.FIND_ELEMENT, {
36
+
37
+ File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
38
+
25
- NameError: name 'i' is not defined
39
+ self.error_handler.check_response(response)
40
+
41
+ File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
42
+
43
+ raise exception_class(message, screen, stacktrace)
44
+
45
+ selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='dep_list']/ul/li[i]"}
46
+
47
+ (Session info: chrome=89.0.4389.90)
26
48
 
27
49
  ```
28
50
 
@@ -104,6 +126,10 @@
104
126
 
105
127
  time.sleep(2)
106
128
 
129
+
130
+
131
+ i += 1
132
+
107
133
  ```
108
134
 
109
135
 
@@ -112,7 +138,7 @@
112
138
 
113
139
 
114
140
 
115
- 変数がi=14と義されていにもかかわらず、このエラーが出る理由がわりません。
141
+ iを含んだものをxpathに指ることはできないでしょう
116
142
 
117
143
 
118
144