0

I'm trying to to use the chrome webdriver inside my python code here:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from sklearn.linear_model import LinearRegression
import time
import numpy as np
from sklearn.svm import SVR
import pytz
from datetime import datetime
from sys import argv, exit
import os, psutil

################################################

X=[]
y=[]
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--headless")
chromeOptions.add_argument("--remote-debugging-port=2212")
chromeOptions.add_argument('--no-sandbox')
chromeOptions.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/root/chromedriver',chrome_options=chromeOptions)
driver.get('https://example.com/')

But after executing the script, I get the following error:

Traceback (most recent call last):
  File "ml.py", line 29, in <module>
    driver = webdriver.Chrome('/root/chromedriver',chrome_options=chromeOptions)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to connect to renderer
  (Session info: headless chrome=90.0.4430.72)

How can I solve this problem? Note that I'm using Ubuntu 18 Cli version

Levi
  • 67
  • 8
  • What version of ChromeDriver are you using? – cody Apr 25 '21 at 12:49
  • Does this answer your question? [WebDriverError: disconnected: unable to connect to renderer](https://stackoverflow.com/questions/46807596/webdrivererror-disconnected-unable-to-connect-to-renderer) – cody Apr 25 '21 at 12:56
  • I think it's an issue with the setup you are running in, I hope you have Chrome installed there. even if you are running with headless, you still need Chrome installed. also, try to comment out the `chromeOptions.add_argument("--headless")` to see if you get something different error. – simpleApp Apr 25 '21 at 13:15
  • @cody how can I check that? – Levi Apr 25 '21 at 18:08
  • @simpleApp Still, I get same error – Levi Apr 26 '21 at 05:27
  • pls review the chrome browser version and chromedriver version. Based on error log , your browser version is "90.0.4430.72" , so pls check or download a compatible version of chromedriver for your version of chrome browser. on google chrome detail can be found using chrome://version/ – simpleApp Apr 26 '21 at 12:27

1 Answers1

0

maybe not the best option but at least I could solve the problem by removing the exiting chromedriver and installing the last updated version.

Levi
  • 67
  • 8