0
運行OS X和Python 3.5.1。WebDriverWait語法錯誤
簡單地想知道WebDriverWait搜索xpath的正確上下文是什麼,然後在加載包含網頁後繼續點擊它。
WebDriverWait(driver, 10000).until(EC.presence_of_element_located(driver.find_element_by_xpath(".//*[@id='maincontent']/section[2]/div[1]/table/tbody/tr[1]/td[7]/button")))
a = driver.find_element_by_xpath(".//*[@id='maincontent']/section[2]/div[1]/table/tbody/tr[1]/td[7]/button")
a.click()
錯誤代碼是如下
Traceback (most recent call last):
File "/Users/hansh/Desktop/markets.py", line 22, in <module>
WebDriverWait(driver, 10000).until(EC.presence_of_element_located(driver.find_element_by_xpath(".//*[@id='maincontent']/section[2]/div[1]/table/tbody/tr[1]/td[7]/button")))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 258, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 712, in find_element
{'using': by, 'value': value})['value']
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":".//*[@id='maincontent']/section[2]/div[1]/table/tbody/tr[1]/td[7]/button"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///var/folders/b3/h2pq8lmx4p11tb5h3m49xbth0000gn/T/tmpb9uhnk6f/extensions/[email protected]/components/driver-component.js:10659)
at FirefoxDriver.prototype.findElement (file:///var/folders/b3/h2pq8lmx4p11tb5h3m49xbth0000gn/T/tmpb9uhnk6f/extensions/[email protected]/components/driver-component.js:10668)
at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/b3/h2pq8lmx4p11tb5h3m49xbth0000gn/T/tmpb9uhnk6f/extensions/[email protected]/components/command-processor.js:12534)
at DelayedCommand.prototype.executeInternal_ (file:///var/folders/b3/h2pq8lmx4p11tb5h3m49xbth0000gn/T/tmpb9uhnk6f/extensions/[email protected]/components/command-processor.js:12539)
at DelayedCommand.prototype.execute/< (file:///var/folders/b3/h2pq8lmx4p11tb5h3m49xbth0000gn/T/tmpb9uhnk6f/extensions/[email protected]/components/command-processor.js:12481)