0

I use Selenium with FirefoxDriver, when instance it, FireFox browser auto open, how we can hide it?

WebDriver driver = new FirefoxDriver();

Thanks,

Huy Hang
  • 1
  • 1
  • 4

4 Answers4

1

You might be able to attach to the window handle using Win32 and hide it, but other than that I don't think it can be done.

The FirefoxDriver in Selenium is meant for automating the real firefox browser (not some representation of it) for UI testing. Because of this the real browser needs to be running for it to work.

If you want a non-viewable UI driver you'll need to use the HtmlUnit driver.

However as the site says:

None of the popular browsers uses the JavaScript engine used by HtmlUnit (Rhino). If you test JavaScript using HtmlUnit the results may differ significantly from those browsers.

So I would be careful trusting the HtmlUnit driver.

src: http://seleniumhq.org/docs/03_webdriver.html#webdriver-implementations

EDIT

Also, I would add that typically the automated testing would be on a dedicated machine with no users. In which case it shouldn't matter weather or not you can see the browser.

Brandon Boone
  • 16,281
  • 4
  • 73
  • 100
  • Yes, but HtmlUnit driver or event HtmlUnit library can not parse this page: https://www.oceanschedules.com/schedules/search.do – Huy Hang Mar 06 '11 at 14:27
  • You might be able to set the user agent and spoof the site. http://stackoverflow.com/questions/4565250/set-user-agent-in-selenium-rc – Brandon Boone Mar 07 '11 at 02:13
1

if you don't want to open the real browser like Firefox, then you should use the Html Unit Driver (Remote Web Driver). Firstly add the namespace and then write your code. Best of Luck.

using OpenQA.Selenium; using OpenQA.Selenium.Remote;

class Program
{
    static void Main(string[] args)
    {
        ICapabilities desiredCapabilities = DesiredCapabilities.HtmlUnit();
        IWebDriver driver = new RemoteWebDriver(desiredCapabilities);

        //your code begins here

     }
 }
harish kumar
  • 31
  • 1
  • 6
0

Also, I would add that typically the automated testing would be on a dedicated machine with no users. In which case it shouldn't matter weather or not you can see the browser.

Starting a GUI is longer than starting a non-gui browser. It's really important when you have a huge project and don't want your test to take an eternity to finish.

Depado
  • 4,811
  • 3
  • 41
  • 63
0

Not sure, what you try to achieve, but as far as I understood you want firefox windows not to interrupt your work while selenium tests are running. So you can run your tests in another desktop. Use for example this tool: Desktops. Easy and cheap solution.

Aleh Douhi
  • 1,958
  • 1
  • 14
  • 13