0

When I create an instance of the Firefox Web driver, it successfully opens Firefox. However, it opens it with two tabs (one "regular" Firefox tab and one IE tab; the IE tab is active and remains active for the duration of the testing unless I manually switch to the tab that the test is actually executing in).

enter image description here

It will run the test in the Firefox tab (i.e. the non-active one).

I'm instantiating my Firefox web driver like this:

var firefoxOptions = new FirefoxOptions()
{
    Profile = new FirefoxProfile(),
    UseLegacyImplementation = false,
    BrowserExecutableLocation = @"C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"
};

firefoxDriver = new FirefoxDriver(firefoxOptions);

firefoxDriver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 10);

I'd include the code for the unit test, too, but the problem occurs during initialization prior to me running any tests.

Also, when I do cleanup like this:

[TestCleanup]
public void Cleanup()
{
    if (firefoxDriver != null)
    {
        firefoxDriver.Close();
        firefoxDriver.Dispose();
    }
}

it closes the tab that the test was running in (the Firefox tab). However, it only closes that tab - the IE tab and the browser both stay open.

This question seems to be somewhat related, but the behavior's somewhat different because Selenium isn't trying to actually execute the test in both tabs - it only ever uses the one tab. Also, the OP there was using Firefox 20.0 and I'm using Firefox 52.2.0.

  • 2
    Use `firefoxDriver.Quit();` instead of `firefoxDriver.Close();` to terminate the browser. – Florent B. Jul 27 '17 at 16:23
  • @FlorentB. For some odd reason I don't understand, `firefoxDriver.Quit()` doesn't seem to have any effect. It doesn't throw any exception or anything like that. Calling `firefoxDriver.Close()` twice works, but it seems like a dumb hack that's masking the actual problem. – EJoshuaS - Stand with Ukraine Jul 27 '17 at 16:29

1 Answers1

1

Simply, we can create profile and use it. I answered here Firefox 44.0.1 opening two tabs , when running selenium webdriver code

Another way, we can create profile pro-grammatically like

FirefoxProfile profile= new FirefoxProfile();
profile.setPreference(“browser.startup.homepage”,”https://...");
WebDriver driver = new FirefoxDriver(profile);

Just use about:config in firefox URL , it will provide settings.

murali selenium
  • 3,847
  • 2
  • 11
  • 20