Forums

webdriver issue with selenium

Hi - I'm trying to use selenium in my PythonAnywhere account and am running into issues with webdrivers. I just updated to the most recent version of selenium (4.1.0) and am using Python 3.8.

Using Chrome, as described here, find_elements returns a dict rather than WebElement, which seems to be an issue related to the installed chromedriver.

from selenium import webdriver
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
browser = webdriver.Chrome(options=chrome_options)
try:
  browser.get("https://pr.nba.com/")
  print(browser.find_elements(By.CLASS_NAME, 'archive__article-link'))
finally:
  browser.quit()

enter image description here

Using Firefox, I get the following error, though I understand the installed version of geckodriver is quite old:

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

The Firefox issue I ran into on my local machine which was solved by installing a geckodriver on a local directory, but I don't know if I can do that in PythonAnywhere.

It looks like that is an issue with the version of selenium when it is used with the chromedriver available on PythonAnywhere. Try downgrading selenium to 3.141.0

That seems to do the trick. Thanks for the quick help.

Hey Guys, sorry to hijack this thread but I am getting a similar error. I am working on a client's project and after updating the Python(3.8) and Selenium(4.2) versions their script is no longer working due to this ‘geckodriver’ error. From reading the link below, it seems like Selenium 4 is not supported. I'm not sure when this article was last updated so is this still the case? If so, what is the latest version of Selenium that can be used? And are there any plans to get support for Selenium 4 in the near future. It's just that it is a dependency for another package that we need to use for this project. Thanks

https://help.pythonanywhere.com/pages/selenium/

You may try downgrading selenium (I think 4.1.3 may be working) or upgrading system image to a newer one ("glastonbury"), in which the most recent version (4.2.0) might be working with Python 3.8 (at least our basic script from the help page worked for me now). Also -- we don't recommend using Firefox with selenium, so maybe try using it with Chromium?

OK, I will try that. I will update this later and let you know if it works. Thanks very much.

Hello deployed selenium api was working fine untill today tried making some request and I get this error

"Message: unknown error: cannot create default profile directory
Stacktrace:
#0 0x5616aa636e89 <unknown>".

Anything changed in PythonAnywhere that could have caused this issue.?

Nothing has changed in this respect recently -- could you try running code from this help page and see if that still works for you?