Not working selenium module on Ubuntu-server

406 Views Asked by At

I'm struggling with this error:

(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

while using selenium module on my Ubuntu-server 22.04. The thing is that the same code works fine on my local PC with the same Ubuntu version.

For avoiding trivial questions:

  • driver location and binary location are correct
  • I use --headless mode
  • I have the same versions of google-chrome and chromedriver

Code:

# initial settings for selenium
driver_location = '/usr/bin/chromedriver'
binary_location = '/usr/bin/google-chrome'

options = Options()
options.binary_location = binary_location
options.add_argument('--headless')

service = Service(driver_location)
driver = webdriver.Chrome(service=service, options=options)

And again, I think I need somehow use the fact that this code works on my local PC. Maybe you guys can advise me what to check...

3

There are 3 best solutions below

0
rastr__ On BEST ANSWER

For people who struggle the same issue, you can try following code, works for me without any problems:

# initial settings for selenium
    driver_location = 'chromedriver_location'
    binary_location = 'google-chrome_location'

    #options = webdriver.ChromeOptions()
    options = Options()
    options.binary_location = binary_location
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument('--headless')
1
undetected Selenium On

Replace:

options.add_argument('--headless')

with:

options.add_argument(''--headless=new'')

and execute your test.

See: DeprecationWarning: headless property is deprecated, instead use add_argument('--headless') or add_argument('--headless=new') on Selenium 4.8.0 Python

0
MikePBrown123 On

I had the same issue with both chrome and edge in Ubuntu. I removed both chrome and edge and reinstalled edge. It could be caused by driver version.

This is what worked for me:

from webdriver_manager.microsoft import EdgeChromiumDriverManager

edge_options = Options()
edge_options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36')
edge_options.add_argument("--headless")    
edge_options.binary_location='/usr/bin/microsoft-edge'

driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()),options=edge_options)