Problem at launch selenium chromedriver: raise an errors

Viewed 502

I'm trying to use Selenium Webdriver in Python project (at Ubuntu 20.04.3 LTS x86_64)

Error:

<stdin>:1: DeprecationWarning: use options instead of chrome_options
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1

Code:

# Setup selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

PROBLEM STARTS HERE

wd = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
2 Answers

Taken from another similar post "chrome_options is deprecated now and you have to use options instead as well as pass the absolute path of the ChromeDriver along with the extension." I think the code below might work since your chrome driver should be in /usr/bin due to the script

# Setup selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome(executable_path='/usr/bin/chromedriver',options=options)

Please check the driver version with the chromium version should be similar

Related