動的Webページ上でHTML DOM要素を見つけるためにSelenium 2.53.6とChromedriverを使用しています。 Webdriverのfind_element_by_xpath()
コマンドを使用して要素を検索しています。下の例のような単一の要素の場合、find_element_by_xpath()
は要素を探します。私はDOM階層内の複数の要素含めるようにパスを拡張するときSelenium Webdriver:find_element_by_xpathが完全なパスを見つけられない
city1 = driver.find_element_by_xpath("//div[@class='post-body-meta']")
はしかし、:
city1 = driver.find_element_by_xpath("//div[@class='post-body-meta']/span[0]")
を、私は(下のエラーを取得するだけでなく、私は多くの異なる要素を試してみた心に留めておきますこの特定のもの):
Traceback (most recent call last):
File "selen_decko.py", line 72, in <module>
city1 = driver.find_element_by_xpath("//div[@class='post-body-meta']/span[0]")
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 293, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 752, in find_element
'value': value})['value']
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='post-body-meta']/span[0]"}
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Mac OS X 10.11.6 x86_64)
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x101468b70>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 173, in __del__
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 149, in stop
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 120, in send_remote_shutdown_command