Trying to get selenium working

Hi all,

Trying to get selenium working and coming across the issue below:
WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://chromedriver.chromium.org/home

Have tried a few things with different errors, but the one I’m getting is based on below:

!export PATH="/data/workspace_files:$PATH"
!export PATH="/data/notebook_files:$PATH"

import os
import sys

driver_path = '/data/notebook_files/chromedriver'
sys.path.insert(0, driver_path)

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

options = Options()
options.binary_location = driver_path
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
service = Service(executable_path=driver_path)
driver = webdriver.Chrome(service=service,options=options)

Has anyone managed to get around this in DataLore?

Hi,

WebDriverException: Message: ‘chromedriver’ executable may have wrong permissions. Please see ChromeDriver - WebDriver for Chrome

You need to set correct permissions for the chromedriver binary. F.e. it could be done with the following code:

os.chmod(driver_path, 0o755)
1 Like

Thanks Igor,

That’s got me to the next step which is awesome, but then now I’m encountering the below:

WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Stacktrace: #0 0x561990bf7aa9 <unknown>

Code below:
!pip install --upgrade webdriver-manager
!pip install --upgrade selenium

# !cd /data/notebook_files/
!sudo apt update
!sudo apt install -y chromium-browser
# !sudo apt install -y chromium-chromedriver
!export PATH="/data/workspace_files:$PATH"
!export PATH="/data/notebook_files:$PATH"

import os

import sys

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
driver_path = r'/data/notebook_files/chromedriver'
sys.path.insert(0, driver_path)
os.chmod(driver_path, 0o755)

options = Options()

# options.binary_location = driver_path

options.binary_location = r'/usr/bin/chromium-browser'
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
service = Service(executable_path=driver_path)
driver = webdriver.Chrome(service=service,options=options)

I’ve made sure to use the suitable version of chromedriver (85.0.4183.83, as you can see I tried to get via terminal but didn’t have much luck there so reverted back to the manually downloaded copy) and have tried a few suggestions from what I could see on the internet but have not had much luck.

Any help is appreciated.

Did you manage to sort out your issue?

I am also struggling with Selenium and browser drivers. I have tried various solutions such as checking the browser version with the driver version. I tried Firefox and Chrome. I tried using the absolute PATH to my local PC and also uploaded drivers to the cloud path ‘/data/notebook_files’.

Here is my python code.
!export PATH=“/data/workspace_files:$PATH”
!export PATH=“/data/notebook_files:$PATH”

import stat
import time
import os

import sys

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

driver_path = ‘/data/notebook_files/chromedriver.exe’

sys.path.insert(0, driver_path)
os.chmod(driver_path, 0o755)
options = Options()

options.binary_location = driver_path
options.add_argument(‘–no-sandbox’)

st = os.stat(“/data/notebook_files/chromedriver.exe”)
os.chmod(“/data/notebook_files/chromedriver.exe”, st.st_mode | stat.S_IEXEC)
browser = webdriver.Chrome()
driver.get(‘http://www.google.com/’);

It seems that it is finding the exe now however I get the following message

“Traceback (most recent call last):
at cell 3, line 23
at /opt/python/envs/default/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py, line 84, in init(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, service, keep_alive)
at /opt/python/envs/default/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py, line 104, in init(self, browser_name, vendor_prefix, port, options, service_args, desired_capabilities, service_log_path, service, keep_alive)
at /opt/python/envs/default/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py, line 286, in init(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
at /opt/python/envs/default/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py, line 378, in start_session(self, capabilities, browser_profile)
at /opt/python/envs/default/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py, line 440, in execute(self, driver_command, params)
at /opt/python/envs/default/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py, line 245, in check_response(self, response)
WebDriverException: Message: unknown error: cannot find Chrome binary Stacktrace: #0 0x55b7eb7024e3 #1 0x55b7eb431c76 #2 0x55b7eb458757 #3 0x55b7eb457029 #4 0x55b7eb495ccc #5 0x55b7eb49547f #6 0x55b7eb48cde3 #7 0x55b7eb4622dd #8 0x55b7eb46334e #9 0x55b7eb6c23e4 #10 0x55b7eb6c63d7 #11 0x55b7eb6d0b20 #12 0x55b7eb6c7023 #13 0x55b7eb6951aa #14 0x55b7eb6eb6b8 #15 0x55b7eb6eb847 #16 0x55b7eb6fb243 #17 0x7f553c9a1b43
[1]”

Could you please assist?