How to hide firefox window on Mac OS X?

543 views
Skip to first unread message

Peng Yu

unread,
Jan 17, 2016, 11:30:30 AM1/17/16
to Selenium Users
Hi, I must use Firefox instead of a headless browser for scrapping,
because I need to download files.

But when I try the following code in Mac OS X. The Firefox window is
still started. Could anybody let me know what the correct way is to
hide Firefox window on Mac OS X?

from xvfbwrapper import Xvfb

vdisplay = Xvfb()
vdisplay.start()

from pyvirtualdisplay import Display
from selenium import webdriver

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

# now Firefox will run in a virtual display.
# you will not see the browser.
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print browser.title
browser.quit()

display.stop()

vdisplay.stop()

--
Regards,
Peng

David

unread,
Jan 17, 2016, 12:59:55 PM1/17/16
to Selenium Users
Do you have the right version of FF for x11? See this: http://afitnerd.com/2011/09/06/headless-browser-testing-on-mac/. There are more online references if you search terms for xvfb Mac (and perhaps include Firefox, Selenium).

David

unread,
Jan 17, 2016, 2:36:12 PM1/17/16
to Selenium Users
Actually, it looks like that option is outdated (FF x11 no longer available). Your best options today are the following:

* use some other truly headless browser like PhantomJS/GhostDriver
* set up FF (x11) on a Linux virtual machine on your Mac (or some other server) and then connect WebDriver to that (remotely)
Reply all
Reply to author
Forward
0 new messages