Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chromedriver for linux32 does not exist - Python Selenium Chromedriver

I'm creating a cross platform python script that executes some commands with selenium. I have two questions:

  1. How come the following script works on windows but doesn't work on Raspberry pi OS 32bit? The only way this works is to remove the webdriver-manager, but this requires manual installation of the webdriver. I'm using a raspberry pi 3
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.utils import ChromeType

options = Options()
options.headless = True
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()), options=options)
driver.get("http://www.google.com")
print(driver.title)

The output is:

pi@raspberrypi:~/Documents/Software $ /bin/python /home/pi/Documents/Software/test.py


====== WebDriver manager ======
Current chromium version is 95.0.4638
Get LATEST chromedriver version for 95.0.4638 chromium
There is no [linux32] chromedriver for browser  in cache
Trying to download new driver from https://chromedriver.storage.googleapis.com/95.0.4638.69/chromedriver_linux32.zip
Traceback (most recent call last):
  File "/home/pi/Documents/Software/test.py", line 10, in <module>
    driver = webdriver.Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()), options=options)
  File "/home/pi/.local/lib/python3.9/site-packages/webdriver_manager/chrome.py", line 32, in install
    driver_path = self._get_driver_path(self.driver)
  File "/home/pi/.local/lib/python3.9/site-packages/webdriver_manager/manager.py", line 30, in _get_driver_path
    file = download_file(driver.get_url(), driver.ssl_verify)
  File "/home/pi/.local/lib/python3.9/site-packages/webdriver_manager/utils.py", line 98, in download_file
    validate_response(response)
  File "/home/pi/.local/lib/python3.9/site-packages/webdriver_manager/utils.py", line 80, in validate_response
    raise ValueError("There is no such driver by url {}".format(resp.url))
ValueError: There is no such driver by url https://chromedriver.storage.googleapis.com/95.0.4638.69/chromedriver_linux32.zip
  1. How can I create a python script that uses selenium webdriver in headless mode and works on every platform? I mean, if I use chromewebdriver in the script, the user who will use the script must have chrome installed, as well as if a firefox the user must have firefox installed. Is there any webdriver that works without external script installations?

Thanks

EDIT:

The problem is not with the webdriver manager but the fact that chromedrivers for chromium do not exist for linux32. In fact at the address: "https://chromedriver.storage.googleapis.com/95.0.4638.69/chromedriver_linux32.zip" there is no chromedriver, but replacing linux32 with linux64 a package is downloaded but not compatible with linux32. The thing I don't understand is if the chromedrivers for linux32 don't exist then why installing them with: "sudo apt-get install chromium-chromedriver" and then removing the webdriver-manager calls from the code, does the python script work? Then there are chromedrivers for linux32, only they are not present in the main chromedriver site. I am using a raspberry pi 3 with chromium 95.0.4638.69.

like image 976
ernestocesario Avatar asked Oct 20 '25 10:10

ernestocesario


1 Answers

  1. As there is no linux32 chromedriver developped by the official team (e.g. https://chromedriver.storage.googleapis.com/index.html?path=99.0.4844.17/), you can't use webdriver_manager because it's looking at their repositories.

Yet a compatible chromedriver version is maintained by the Raspian team, so in order to make it works you need to :

  • Install chromedriver for raspberry. e.g. for Linux:

    sudo apt-get install chromium-chromedriver
    
  • When you instantiate your driver, you need to tell him where to find this chromedriver. Plus, you should also state that you use Chromium instead of Chrome (if so):

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    
    options = Options()
    # browser is Chromium instead of Chrome
    options.BinaryLocation = "/usr/bin/chromium-browser"
    # we use custom chromedriver for raspberry
    driver_path = "/usr/bin/chromedriver"
    driver = webdriver.Chrome(options=options, service=Service(driver_path))
    
  • Then you're good to go:

    driver.get("https://stackoverflow.com/")
    
  1. If you need a code that works for every platform, the best option I found so far is to distinguished raspberry pi from the other system:

    import platform       
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    
    options = Options()
    # a few usefull options
    options.add_argument("--disable-infobars")
    options.add_argument("start-maximized")
    options.add_argument("--disable-extensions")
    options.add_argument("--headless") # if you want it headless
    
    if platform.system() == "Linux" and platform.machine() == "armv7l":  
        # if raspi
        options.BinaryLocation = ("/usr/bin/chromium-browser")
        service = Service("/usr/bin/chromedriver")
    else: # if not raspi and considering you're using Chrome
        service = Service(ChromeDriverManager().install())           
    
    driver = webdriver.Chrome(
        service=service,
        options=options
        )
    

Considering your question about not having to install Chrome manually to make Selenium works, you could probably install Chrome through a script to be sure that the user has it. It will also work for a Docker use, e.g. for a DockerFile with a Linux amd64 environment:

   RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
   RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy instal
like image 176
aduverger Avatar answered Oct 22 '25 02:10

aduverger