简体   繁体   中英

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!

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM