1

First of all , i know that this question has been asked quite a lot here .Just making it clear that i have read most accepted answers and followed all steps properly , still getting this error as mentioned in question. Here's my script down below along with all other information

[ I am using selenium with chromedriver trying to use it with chromium browser in headless mode running ubuntu 20 ]

cat test.py

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.binary_location = '/usr/bin/chromium-browser'

driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver')
driver.get("https://www.google.com")
print(driver.title)
print ("Headless Chrome Initialized")
driver.quit()

python3 test.py

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py", line 72, in start                                           self.process = subprocess.Popen(cmd, env=self.env,
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__           self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)       FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/bin/chromedriver'
                                                                       During handling of the above exception, another exception occurred:    
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver')
  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 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

What steps i followed

sudo apt install chromium-browser
python3 -m pip install selenium
wget https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip
unzip chromedriver*
chmod +x chromedriver
sudo mv chromedriver /usr/local/bin/
sudo chown root:root /usr/local/bin/chromedriver
sudo chmod 0755 /usr/local/bin/chromedriver

Verifying Everything together

╭─[localhost] as xd003 in ~
╰─➤ lsb_release -a | grep Description && \
apt -qq list python3 && \
apt -qq list chromium-browser && \
which chromedriver && \
which chromium-browser && \
echo $PATH

No LSB modules are available.
Description:    Ubuntu 20.04 LTS
python3/focal,now 3.8.2-0ubuntu2 arm64 [installed]
chromium-browser/focal-updates,now 81.0.4044.129-0ubuntu0.20.04.1 arm64 [installed]
/usr/local/bin/chromedriver
/usr/bin/chromium-browser
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Everything looks good me , can someone please suggest what am i doing wrong ?

The Ubuntu20 i am running locally is a Ubuntu Proot which i am using on my android device

Sachin
  • 845
  • 2
  • 18
  • Does this answer your question? [Selenium using Python - Geckodriver executable needs to be in PATH](https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path) – Arount Jun 23 '20 at 10:17
  • i had already read the accepted answer there , only thing i did different was this step - export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step ... instead of this i did sudo mv geckodriver /usr/local/bin/ although this should ideally definitely work – Sachin Jun 23 '20 at 10:22
  • I haven't realized you explicitly put `/usr/local/bin/geckodriver` path as argument, my bad. – Arount Jun 23 '20 at 10:26
  • I see you did a `chmod +x`, are you sure it was with the same user running the Python script? – Arount Jun 23 '20 at 10:28
  • @Arount yes definitely , i am the only user – Sachin Jun 23 '20 at 10:28
  • Could you update your whole code to `import os; print(os.path.isfile('/usr/local/bin/geckodriver'))`, execute it and give me the output pls? – Arount Jun 23 '20 at 10:35
  • @Arount sure ╭─[localhost] as xd003 in ~ ╰─➤ cat test2.py import os; print(os.path.isfile('/usr/local/bin/geckodriver'))% ╭─[localhost] as xd003 in ~ ╰─➤ python3 test2.py True – Sachin Jun 23 '20 at 10:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/216483/discussion-between-arount-and-sachin). – Arount Jun 23 '20 at 10:39
  • Is `/usr/local/bin` on your PATH? You just need to make sure it is, since that's where you put `chromedriver`. – Bryan Oakley Jun 25 '20 at 04:27
  • @BryanOakley yes sir , it is ╭─[localhost] as xd003 in ~ ╰─➤ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games – Sachin Jun 25 '20 at 04:29
  • Also updated in question - verification section – Sachin Jun 25 '20 at 04:39

2 Answers2

2

After days of figuring this out , i finally was able to get this error fixed.

So as i had mentioned i am running Prooted Ubuntu 20 on Android Device . Now here the linux kernel architecture being aarch64 seems not supported by the official chrome webdriver - https://chromedriver.chromium.org

To fix this , just download a chromedriver compiled for arm64 variant .You can always get the latest one from here - https://github.com/electron/electron/releases

In short , everything else was perfect ,just needed to replace the wget link by - https://github.com/electron/electron/releases/download/v8.3.4/chromedriver-v8.3.4-linux-arm64.zip

PS / Maybe if the error was something like - linux kernel architecture not supported , it would have been lot easier to fix it but nevermind.

Sachin
  • 845
  • 2
  • 18
0
  1. chromedriver I always pass to constructor
  2. PATH error occurs if it cannot be found (see example below where I deliberately pass incorrect param)
  3. this driver does not work with chromium, only chrome. Hence reason to keep drivers separate from /usr/bin dir
import time, os, datetime, json, requests, re, subprocess
from distutils.version import StrictVersion
from pathlib import Path
import xmlplain
import selenium
from selenium import webdriver

def get_release(v):
    r = re.compile(f'^(83\.[0-9]+\.[0-9]+).*linux.*$')
    maxrel = "0.0.0"
    pos = 0
    for i, rel in enumerate(v):
        if r.match(rel) is not None and StrictVersion(r.split(rel)[1]) > StrictVersion(maxrel): 
            maxrel = r.split(rel)[1]
            pos = i

    return v[pos]

def cmd(cmd:str, assertfail=True) :
    up = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
    str = [l.rstrip().decode() for l in up.stdout]
    exitcode = up.wait()
    if assertfail: assert exitcode == 0, f"[{exitcode}] {cmd} {str}"
    return exitcode,  str


if __name__ == '__main__':
    # os.environ["DISPLAY"] = ":0.0"

    # find latest driver available
    resp = requests.get("https://chromedriver.storage.googleapis.com")
    raw = xmlplain.xml_to_obj(resp.content, strip_space=True, fold_dict=False)
    v = get_release([e["Contents"][0]["Key"] for e in raw["ListBucketResult"] if "Contents" in e.keys()])
    # download if required
    if not Path.cwd().joinpath(v.split("/")[0]).is_dir():
        cmd(f"mkdir {v.split('/')[0]}")
        cmd(f"wget https://chromedriver.storage.googleapis.com/{v} -O {v}")
        cmd(f"unzip {v} -d {v.split('/')[0]}/")
    # hit a webpage
    try:
        driver = webdriver.Chrome(f"unknown/chromedriver")  # Optional argument, if not specified will search path.
    except selenium.common.exceptions.WebDriverException as e:
        print(e)
    options = webdriver.ChromeOptions()
    options.add_argument('--no-sandbox')
    options.add_argument('--headless')
    options.add_argument('--disable-dev-shm-usage')
    options.binary_location = '/usr/bin/chromium-browser'
    options.binary_location = '/usr/bin/google-chrome'
    driver = webdriver.Chrome(f"{v.split('/')[0]}/chromedriver", options=options)  # Optional argument, if not specified will search path.
    driver.get('https://www.google.com')
    print(driver.title)
    print ("Headless Chrome Initialized")
    driver.quit()

output:

Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Google
Headless Chrome Initialized
Rob Raymond
  • 8,924
  • 2
  • 6
  • 17
  • You said chromedriver doesn't work with chromium but I have seen many people here on SO asking about it and many using it as well probably. Here are 2 such questions where answers with decent upvotes have suggested that we can use chromium browser instead of chrome - https://stackoverflow.com/questions/5731953/use-selenium-with-chromium-browser https://stackoverflow.com/questions/24999318/selenium-use-chromium-instead-of-google-chrome. – Sachin Jun 25 '20 at 11:22
  • Also read my solution , i think chromedriver was wrongly outputting it needs to be in path when it should have rightly said - linux kernel architecture not supported. Anyways thanks for your input – Sachin Jun 25 '20 at 11:25
  • Both your points are correct. When chromedriver is incompatible with browser produced errors quite often do not say this. When I use this chromedriver with chromium I get an DevToolsActivePort error but not a compatibility error and not PATH error. Drivers also need to be compiled for architecture - raspberry pi requires a driver compiled for ARM processors. This you have noted as well. IMHO get working with chrome then move to chromium knowing there is work to find an appropriately built driver. – Rob Raymond Jun 25 '20 at 11:56
  • yeah i would have used chrome if possible but in the prooted ubuntu20 i am running , chrome can't be installed by any means. Anyways finally got it solved by using a arm64 chromedriver and that too with chromium . For that devtools error which you mentioned i was facing it few days back ,i solved it by adding these 2 lines – Sachin Jun 25 '20 at 12:22
  • options.add_argument('--disable-dev-shm-usage') options.add_argument("--remote-debugging-port=9222") – Sachin Jun 25 '20 at 12:22