Pareshkumar Pareshkumar - 5 months ago 142x
Java Question

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

but I don't want to do it.

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


Finally I found the solution for those who is using windows Machine for running the Tests using any method. Well, implementation is not in java but you can do it very easily.

Use AutoIt tool. It has all the capability to handle windows. It is free Tool.

  1. Install AutoIt:

  2. Open the Editor and write below code for Hiding any window.

    AutoItSetOption("WinTitleMatchMode", 2)
    WinSetState("Title Of Your Window", "", @SW_HIDE) 
  3. To Unhide it, you can use below line of code.

    AutoItSetOption("WinTitleMatchMode", 2)
    WinSetState("Title Of Your Window", "", @SW_SHOW)

    WinTitleMatchMode has different options which can be used to match Windows title.

    1 = Match the title from the start (default)`
    2 = Match any substring in the title
    3 = Exact title match
    4 = Advanced mode, see Window Titles & Text (Advanced)

So what I am doing is: I have created exe of a small program and passing parameter as command line argument as below.

Runtime.getRuntime().exec("C:/Diiinnovation/HideNSeek.exe 0 \"" + "Mozilla Firefox" + "\"");

in HideNSeek.exe - I have below AutoIt Code:

AutoItSetOption("WinTitleMatchMode", 1) 

if $CmdLine[0] > 0 Then
    if $CmdLine[1] == 0 Then
        WinSetState($CmdLine[2], "", @SW_HIDE)    
    ElseIf $CmdLine[1] == 1 Then
        WinSetState($CmdLine[2], "", @SW_SHOW)          

$CmdLine[] is an array which will have all command line parameters..

$CmdLine[0] = number of Parameter
$CmdLine[1] = 1st Parameter after Exe Name 

If there is any space in the Window Title then you have to use double quotes to pass it as a command line parameter like above.

Below Line of code will execute AutoIt exe and if I pass '0' in 1st parameter then it will hide the window and if I will pass '1' then it will unhide windows matching the title.

Runtime.getRuntime().exec("C:/Diiinnovation/HideNSeek.exe 0 \"" + "Mozilla Firefox" + "\"");

I hope this will help you. thanks!