9

I have a python test and I want to run it without opening the firefox

I want to hide it so how can I do this ?

any help ?

munia ali
  • 91
  • 1
  • 1
  • 4
  • "Python test" is a bit unclear. You mean you want to run a site UI test using selenium? In that case, you can use PhantomJS (with selenium as well), it is a browser running in background without any kind of graphical interface and, obviously, windows. – Andrew Che Mar 16 '17 at 09:10

3 Answers3

23

Headless:

# pip install selenium
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument('--headless')

driver = webdriver.Firefox(options=options)
driver.get('https://www.google.com/doodles')

print('Title: "{}"'.format(driver.title))
driver.quit()
gil9red
  • 946
  • 11
  • 26
4

You can try to set negative window position to hide browser:

driver.set_window_position(-3000, 0) # driver.set_window_position(0, 0) to get it back

or try PhantomJS headless browser, that allow to run UI tests without displaying browser window

Andersson
  • 51,635
  • 17
  • 77
  • 129
0

Have a look at this answer: https://stackoverflow.com/a/6300672/2929488

#!/usr/bin/env python

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()
Community
  • 1
  • 1
Abaddon666
  • 1,533
  • 15
  • 31