1

I have already read a couple of threads about this problem but none of them really helped me so here goes. I am trying to use selenium webdriver on google colab. i had some problems installing it but finally with the code below, i was able to install it:

!pip install selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
wd.get("https://www.webite-url.com")

however, now when i run this two lines of codes:

from selenium import webdriver
driver = webdriver.Chrome()

this is the error I get:

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.)
5
  • normally web browser uses local video card and monitor to display window. If you run code on server then it try to use video card and monitor in this server but server usually don't have video card and monitor - because nobody could see this screen (except server's admin). And this can make problem. Chrome can run without displaying window when you use option headless and then it can run on server. (Server without monitor is called "headless" because monitor looks like it head)
    – furas
    Jul 28, 2019 at 14:03
  • @furas i think the headless option is already there in the code am i right?
    – Mahdi_J
    Jul 28, 2019 at 14:29
  • you have to use headless in every webdriver.Chrome() - which runs new browser.
    – furas
    Jul 28, 2019 at 14:37
  • can you show me how please? @furas
    – Mahdi_J
    Jul 28, 2019 at 21:10
  • you already have it in your question - webdriver.Chrome('chromedriver',chrome_options=chrome_options). You have to use chrome_options with --headless in every webdriver.Chrome()
    – furas
    Jul 28, 2019 at 21:14

1 Answer 1

1

It runs on server which doesn't have video card and monitor so you have to always use --headless and maybe other options too

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options)

driver.get("...your_url...")

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.