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.