Forums

Selenium NoSuchElementException on pythonanywhere but not locally

the line that raises the exception is:

driver.find_element(By.LINK_TEXT, "FIND IN A STORE").click()

I have other driver.find_element() lines in my code that do work on pythonanywhere.

It is running locally as expected, but raises the exception in the deployed file.

for more context, I am using driver.implicitly_wait(20) so I assume waiting time shouldn't be an issue.

It could be that the text "FIND IN A STORE" is wrapped in a font tag. I would try an XPath search for the element and see if that works. If it does then the driver.find_element(By.LINK_TEXT, .. ) does not work when the text is wrapped in another tag.

thanks for your help. I changed to use XPATH, but got the same result. It works as expected locally, but not in python anywhere environment.

Another possibility is that the site you are accessing is returning a different page depending on the IP address of the browser used to access it. The best way to work out what is going on is to use the driver.get_screenshot_as_file(filename) method to capture what is displayed in the browser and take a look there; that will hopefully clarify what's going on.

thanks for that. So I added this code, and all I get is a picture with the text: "your login request was unsuccessful, please try again"

Now obviously that is not what I was expecting. This is a retail website I am scraping. After some further testing, it appears every time I call driver.find_element() it raises a NoSuchElementException.

That you are reaching other page, not the one you expect.