Headless Selenium + Xvfb + Chrome on OSX 10.11
Asked Answered
P

2

15

Okay, so first I learned that Xvfb wasn't included with my OS X version, so I installed it from http://www.xquartz.org/.

and that seemed to have worked:

which xvfb
/opt/X11/bin/xvfb

But when I try using it with either pyvirtualdisplay and xvfbwrapper, following advice I found on this question How do I run Selenium in Xvfb? My script runs without errors but just opens in a Chrome browser window:

from selenium import webdriver
from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 600))
display.start()

browser = webdriver.Chrome()
browser.get('google.com')

Am I doing something wrong here?

Pyrochemical answered 30/11, 2015 at 3:32 Comment(0)
C
9

I believe that Chrome is built for Quartz ui framework, so it ignores the X11 windowing engine. You will need to install an X11 version of a browser and then execute that.

Ceaseless answered 4/12, 2015 at 9:11 Comment(2)
Where can I install this?Afoul
Is this only for Mac? Aka will it work on my linux box with Chrome?Reena
G
-1

For me, this code works fine on OSX 10.13. You don't need pyvirtualdisplay, because you can run chrome in headless mode. Just download chromedriver that fits to your chrome version and put it to usr/local/bin

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--mute-audio')
options.add_argument('--lang=de')
options.add_argument('--window-size=800,600')
options.add_argument('--disable-notifications')
options.add_argument('--enable-popup-blocking')

browser = webdriver.Chrome(chrome_options=options, executable_path='/usr/local/bin/chromedriver')

browser.get('some url')
Godfree answered 14/4, 2022 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.