0

I have a problem with executing the following script:

from selenium import webdriver
driver = webdriver.Chrome("C:\\...\\chromedriver.exe")
driver.get("https://www.google.com")
driver.maximize_window()
driver.close()

I'm getting following error:

Traceback (most recent call last):
File "C:\...\Se_Test2.py", line 6, in <module>
driver = webdriver.Chrome("C:\\...\\chromedriver.exe")
File "C:\...\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\...\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\...\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\...\webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\...\remote_connection.py", line 374, in execute
return self._request(command_info[0], url, body=data)
File "C:\...\remote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "C:\...\_request_methods.py", line 118, in request
return self.request_encode_body(
File "C:\...\_request_methods.py", line 217, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "C:\...\poolmanager.py", line 432, in urlopen
conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
File "C:\...\poolmanager.py", line 303, in connection_from_host
return self.connection_from_context(request_context)
File "C:\...\poolmanager.py", line 328, in connection_from_context
return self.connection_from_pool_key(pool_key, request_context=request_context)
File "C:\...\poolmanager.py", line 351, in connection_from_pool_key
pool = self._new_pool(scheme, host, port, request_context=request_context)
File "C:\...\poolmanager.py", line 265, in _new_pool
return pool_cls(host, port, **request_context)
File "C:\...\connectionpool.py", line 196, in __init__
timeout = Timeout.from_float(timeout)
File "C:\...\timeout.py", line 190, in from_float
return Timeout(read=timeout, connect=timeout)
File "C:\...\timeout.py", line 119, in __init__
self._connect = self._validate_timeout(connect, "connect")
File "C:\...\timeout.py", line 156, in _validate_timeout
raise ValueError(
ValueError: Timeout value connect was <object object at 0x000001ADCD248790>, but it must be an int, float or None.

Process finished with exit code 1

The same error is with Firefox driver.

I use Pycharm. Selenium is installed using pip install.

I've tried with older drivers for Chrome, Firefox, and get the same error. Geckodrover and chromedriver are both added to PATH.

Please help me!

yser
  • 1
  • Can you try and set the timeout, after driver = webdriver.Chrome(...) insert this line: driver.set_page_load_timeout(30) – sc-leeds Aug 01 '23 at 14:27
  • you may try this way https://stackoverflow.com/questions/76810565/python-selenium-nosuchdriverexception-unable-to-obtain-chromedriver-using-sel/76812538#76812538 – Ajeet Verma Aug 01 '23 at 14:30

1 Answers1

0

If you are using Selenium 4 or above, you should use Service class to set the driver.exe path.

Try this:

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

service = Service('C:\\...\\chromedriver.exe"')
driver = webdriver.Chrome(service=service)
driver.get("https://www.google.com/")
driver.maximize_window()
driver.close()

Reference - Driver Service Class

Using Selenium Manager: Not sure which version of selenium you are using, if you are on latest version say selenium v4.6.0 or higher, you don't have to worry about setting the path of chromedriver.exe, selenium will internally do it for you, code can be as simple as below:

from selenium import webdriver

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

Shawn
  • 4,064
  • 2
  • 11
  • 23
  • I have a Selenium version 4.10.0. Your script with driver = webdriver.Chrome() ist working with the same error as before, "timeout". Maybe it is some software, which slows Python down? – yser Aug 02 '23 at 08:50