Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide Firefox window (Selenium WebDriver)?

When I execute multiple test simultaneously, i don't want to keep Firefox browser window visible.. I can minimize it using selenium.minimizeWindow() but I don't want to do it.

Is there any way to hide Firefox window? I am using FireFox WebDriver.

like image 300
OverrockSTAR Avatar asked Mar 20 '11 19:03

OverrockSTAR


People also ask

How do I close Firefox in Selenium?

WebDriver webdriver; ProfilesIni profile = new ProfilesIni(); FirefoxProfile myprofile = profile. getProfile("myProfileName"); webdriver = new FirefoxDriver(myprofile); Now webdriver. quit(); will close the firefox browser after the test has run.

How do I make Selenium undetectable in Firefox?

webdriver is set to true by default when using Selenium. This variable will be present in Chrome as well as Firefox. This variable should be set to "undefined" to avoid detection. A proxy server can also be used to avoid detection.


1 Answers

Python

The easiest way to hide the browser is to install PhantomJS. Then, change this line:

driver = webdriver.Firefox() 

to:

driver = webdriver.PhantomJS() 

The rest of your code won't need to be changed and no browser will open. For debugging purposes, use driver.save_screenshot('screen.png') at different steps of your code or just switch to the Firefox webdriver again.

On Windows, you will have to specify the path to phantomjs.exe:

driver = webdriver.PhantomJS('C:\phantomjs-1.9.7-windows\phantomjs.exe') 

Java

Have a look at Ghost Driver: How to run ghostdriver with Selenium using java


C#

How to hide FirefoxDriver (using Selenium) without findElement function error in PhantomDriver(headless browser)?

like image 115
Stéphane Bruckert Avatar answered Sep 30 '22 04:09

Stéphane Bruckert