ロジャー
ロジャー

Reputation: 357

chrome fails to load with python selenium chromedriver

I have tested the code on my PC with Ubuntu 17.10. Chrome launches with UI so everything is normal.

The Vultr instasnce is with Ubuntu 16.04, Python 3, Selenium, Google-Chrome, Chromedriver and xvfb installed. Default user is root.

chromedriver-2.33.506092 is on /usr/bin/chromedriver, while Google-Chrome-62.0.3202.75 is on /usr/bin/google-chrome

However, running it on a Vultr instance, it gives this error: https://pastebin.com/RJX6Ynxe

Below is part of the code.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1024, 768))
display.start()

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
self.driver = webdriver.Chrome(chrome_options=chrome_options)

This is the service-log: https://pastebin.com/s6Nw3Jxc

Would anyone know how to fix this?

Thanks!

Upvotes: 5

Views: 10288

Answers (1)

deathangel908
deathangel908

Reputation: 9709

This issue is related to chrome driver only. The cause of the issue is described here.

To be specific when you run chrome in headless mode you need to include flag --no-sandbox:

chrome_options.add_argument('--no-sandbox')

Upvotes: 11

Related Questions