1

I am learnig Selenium and I encountered a problem where one of my projects can lanuch a browser but the other one throws errors. Both of them have the same code right now, bot have the webdriver copied to project folder. If I leave this line like it is:

driver = webdriver.Chrome()

I get the following error:

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

If I change it to this:

driver = webdriver.Chrome(r"C:\Users\user\PycharmProjects\Sel\chromedriver.exe")

I get the following error:

ValueError: Timeout value connect was <object object at 0x0000022461CC8720>, but it must be an int, float or None.

I don't understand why is it happening, both of these projects are the same, configured in the same name, the only difference. So far the whole code looks like this:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC



driver = webdriver.Chrome(r"C:\Users\user\PycharmProjects\Sel\chromedriver.exe")

driver.get('https://the-internet.herokuapp.com/drag_and_drop')
driver.implicitly_wait(10)

Update

I am 100% sure I am using latest Selenium, as per the image below, as per this image

Mlomow
  • 13
  • 3

3 Answers3

0

Looks like you are using older version of Selenium. Upgrade to the latest version of selenium(4.11.0), then you don't have to specify the path of chromedriver.exe. Selenium will internally download and manage the drivers for you.

Code can be as simple as:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.google.com")

For more infor, few useful answers:

UPDATE: If you are using latest selenium, then below line is not correct:

driver = webdriver.Chrome(r"C:\Users\user\PycharmProjects\Sel\chromedriver.exe")

You need to use Service class to configure the driver path, as below:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service("C:/Users/user/PycharmProjects/Sel/chromedriver.exe")
driver = webdriver.Chrome(service=service)
driver.get("https://www.google.com")
Shawn
  • 4,064
  • 2
  • 11
  • 23
  • I am using Selenium 4.11.2 in both projects. As I've said - they are configured in exactly the same way. Same Python, same PyCharm, same Selenium, same machine, same webdriver, same browser. – Mlomow Aug 10 '23 at 13:30
  • Your edit gives me the following error: 'Traceback (most recent call last): File "C:\Users\user\PycharmProjects\Exc\venv\main.py", line 11, in driver = webdriver.Chrome(service=service) TypeError: __init__() got an unexpected keyword argument 'service' ' And it still doesn't explain why these two projects work differently if everything is identical. – Mlomow Aug 10 '23 at 13:53
  • Am mostly certain the selenium running in your project is not `4.11.2`. Can you double check the version? In PyCharm, go to Python Interpreter and check Selenium's version. Share the screenshot of it to your question. – Shawn Aug 10 '23 at 13:57
  • 1
    I checked it again and yes, this is the latest Selenium. Image is in the OP now. – Mlomow Aug 10 '23 at 14:08
0

Given the image as you are on Selenium v4.11.2 you no more need to pass the absolute path of the ChromeDriver binary, as Selenium Manager being fully integrated is invoked transparently by the Selenium bindings when no browser driver is detected on the PATH or no third party driver manager is being used.

You just need to ensure that:

  • The ChromeDriver is removed from the path:

    C:\Users\user\PycharmProjects\Sel\
    
  • The system PATH variable doesn't contains the following entry:

    C:\Users\user\PycharmProjects\Sel\
    

and you can simply use the line of code:

driver = webdriver.Chrome()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Tried that, removing project address from PATH variable results in following error: selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH – Mlomow Aug 14 '23 at 15:19
0

I ran into the same error yesterday. If it is the same, I was able to fix it by directly editing Lib\site-packages\selenium\webdriver\remote\remote_connection.py

Replace the 3 occurrences of _timeout = socket._GLOBAL_DEFAULT_TIMEOUT

with _timeout = urllib3.util.timeout._DEFAULT_TIMEOUT

I think it's related to this bug in Jenkins https://bugs.launchpad.net/python-jenkins/+bug/2018567

This was in v3.141, but I can see the code for setting the default timeout within that module hasn't changed in v4.

See also

pk1
  • 24
  • 2
  • Oh my Zeus, this helped! I still don't get it why one of my projects worked fine, and the other one required me to make changes to Python packages.... I just have to keep my fingers crossed it will never happen again, lol – Mlomow Aug 16 '23 at 09:21