python硒 - 鼻琴感应,尽管发现了该值
我在AWS上的Lambda功能中运行了Python Selenium脚本。
使用XPath,我尝试找到分页按钮移至下一页。
我使用以下代码:
button_next = driver.find_element_by_xpath('//a[@data-at="pagination-next"]')
代码有效,因为我能够打印它并将事件提取URL并打印出来:
url = button_next.get_attribute("href")
但是在日志中,我会收到以下错误,但是在我能够打印之后:
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@data-at="pagination-next"]"}
(Session info: headless chrome=65.0.3325.181)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.14.255-276-224.499.amzn2.x86_64 x86_64)
: NoSuchElementException
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 69, in lambda_handler
button_next = driver.find_element_by_xpath('//a[@data-at="pagination-next"]')
File "/opt/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 368, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/opt/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 858, in find_element
'value': value})['value']
File "/opt/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/opt/python/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@data-at="pagination-next"]"}
(Session info: headless chrome=65.0.3325.181)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.14.255-276-224.499.amzn2.x86_64 x86_64)
什么是问题这里?尽管XPath以前刚刚起作用,但为什么我会遇到此错误。
I'm running a python selenium script in a lambda function on AWS.
With xpath I try to find the pagination button to move to the next page.
I use the following code:
button_next = driver.find_element_by_xpath('//a[@data-at="pagination-next"]')
The code works, because I'm able to print it and event extract the URL and also print it:
url = button_next.get_attribute("href")
But in the log I get the following error but after I was able to print it:
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@data-at="pagination-next"]"}
(Session info: headless chrome=65.0.3325.181)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.14.255-276-224.499.amzn2.x86_64 x86_64)
: NoSuchElementException
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 69, in lambda_handler
button_next = driver.find_element_by_xpath('//a[@data-at="pagination-next"]')
File "/opt/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 368, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/opt/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 858, in find_element
'value': value})['value']
File "/opt/python/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/opt/python/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@data-at="pagination-next"]"}
(Session info: headless chrome=65.0.3325.181)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.14.255-276-224.499.amzn2.x86_64 x86_64)
What is the issue here? Why do I get this error, although the xpath just worked before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所需的元素是动态元素,因此要单击 clickable 元素,您需要诱导 webdriverwait 对于 emeltion_to_be_clickable()以下 定位器策略 :
使用 css_selector ::::
使用 xpath :
注意:您必须添加以下导入:
另外,请确保:
The desired element is a dynamic element so to click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
Using XPATH:
Note: You have to add the following imports :
Additionally, ensure that: