1

I have a script in google Colab that uses Selenium for automating some Chrome tasks. The weird thing is that this script worked perfectly until today. Suddenly, when I run my script, I get this error that I did not get before:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-26-c1c375032a08> in <cell line: 10>()
     15 
     16     # Specify the path to chromedriver executable
---> 17     driver = webdriver.Chrome("chromedriver", options=options)
     18     driver.get(url)
     19     print(driver.title)

TypeError: WebDriver.__init__() got multiple values for argument 'options'

My code is the following:

Getting Chromedriver

%%shell
# Ubuntu no longer distributes chromium-browser outside of snap
#
# Proposed solution: https://askubuntu.com/questions/1204571/how-to-install-chromium-without-snap

# Add debian buster
cat > /etc/apt/sources.list.d/debian.list <<'EOF'
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster.gpg] http://deb.debian.org/debian buster main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster-updates.gpg] http://deb.debian.org/debian buster-updates main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-security-buster.gpg] http://deb.debian.org/debian-security buster/updates main
EOF

# Add keys
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DCC9EFBF77E11517
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A

apt-key export 77E11517 | gpg --dearmour -o /usr/share/keyrings/debian-buster.gpg
apt-key export 22F3D138 | gpg --dearmour -o /usr/share/keyrings/debian-buster-updates.gpg
apt-key export E562B32A | gpg --dearmour -o /usr/share/keyrings/debian-security-buster.gpg

# Prefer debian repo for chromium* packages only
# Note the double-blank lines between entries
cat > /etc/apt/preferences.d/chromium.pref << 'EOF'
Package: *
Pin: release a=eoan
Pin-Priority: 500


Package: *
Pin: origin "deb.debian.org"
Pin-Priority: 300

Installing dependencies

!apt-get update
!apt-get install chromium chromium-driver
!pip3 install selenium

!pip install selenium
!pip3 install -U selenium
!api-get update
!api-get install -y chromium-browser
!pip3 install webdriver-manager
!apt install chromium-chromdriver

The code to try to run the webdriver:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import WebDriverException

try:
  url = "http://example.com/"
  options = Options()
  options.add_argument("--headless")
  options.add_argument("--no-sandbox")
  driver = webdriver.Chrome("chromedriver", options=options)
  driver.get(url)
  print(driver.title)
  driver.quit()
except WebDriverException as e:
  print(str(e))

Refactoring my code to remove the initial parameter "chromedriver" seems to work, but I do not understand why the code worked perfectly before and not now.

  • does this solve your problem https://stackoverflow.com/questions/76428561/typeerror-webdriver-init-got-multiple-values-for-argument-options ? – Ajeet Verma Jun 08 '23 at 06:12
  • Hi! Thanks for the comment. Actually, I already tried that, but I still get the same error with that –  Jun 08 '23 at 06:14

3 Answers3

1

This is due to changes in selenium 4.10.0: https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e

Changes_in_selenium_4_10_0

Note that the first argument is no longer executable_path, but options. (That's why it complains that you're passing it in twice.)

If you want to pass in an executable_path, you'll have to use the service arg now.

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

service = Service(executable_path="chromedriver")
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
  • If anyone else finds their way here because pyhtml2pdf was affected by this breakage, there's a pull request based on this answer that fixes the problem: https://github.com/kumaF/pyhtml2pdf/pull/2 – macnewbold Jun 09 '23 at 17:15
0

The same happened to me today. Basically Selenium released version 4.10 and they totally removed a bunch of deprecated code, including such way of instantiating the webdriver with a string path to the driver.

Here you can see what is the correct way of doing so (and only one as of 4.10): https://stackoverflow.com/a/70099102/9453904

Basically you have to use the Service object, and the automated ChromeDriverManager (pip install webdriver-manager) which will download the correct webdriver for you:

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

opts = Options()
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=opts)

driver.get(url)
Leonardo Kuffo
  • 901
  • 9
  • 10
0

I had a similar problem to you, in that I used the Debian Buster method, sourced from a variety of internet sources. However, even this method has stopped working for me as of late. I used the following comment section to fix the issues I had : Link . If you scroll all the way to the bottom, people have been posting updates on code that lets them use selenium with google colab. As of today, (8/16), the code they had at the bottom works fine.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 20 '23 at 11:31