1

The following codes run with python selenium 3.14 without an issue:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(options=chrome_options)

But after upgrading selenium package from 3.14 to 4.1, code above doesn't work anymore. The complete exception messages:

Traceback (most recent call last):
  File "selenium.py", line 8, in <module>
    browser = webdriver.Chrome(options=chrome_options)
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 268, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 359, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "/home/python/selenium/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 211, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: 

Nothing is specified after selenium.common.exceptions.WebDriverException: Message:, I couldn't figure out what goes wrong.

chrome version and chromedriver version is as follows:

user@ubuntu:~/python$ google-chrome --version
Google Chrome 96.0.4664.110 

user@ubuntu:~/python$ chromedriver -v
ChromeDriver 96.0.4664.45 (76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@

Any help would be appreciated.

oeter
  • 627
  • 2
  • 8
  • 23

2 Answers2

1

You can try passing the absolute path of the chromedriver binary as follows:

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

s = Service('/path/to/chromedriver')
chrome_options = Options()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(service=s, options=chrome_options)

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

I'm not sure if you have enabled the terminal proxy. I encountered the same issue, but it was resolved by turning off the proxy. I'm using Mac system, and initially, I added the following proxies to my .zshrc file:

export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

I found that it was these three proxies that caused me to encounter the same problem as you. If you are in the same situation as me, you can add the following statements in your .zshrc file:

export no_proxy="localhost,127.0.0.1"