Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I've researched this to some extent already by searching StackOverflow and SQA, but cannot find the answer.

Is it possible to open a new WebDriver browser window from the current FirefoxDriver (IWebDriver) instance, or do I need to instantiate a new FirefoxDriver instance? It would be nice to open a new tab, but I read that this is not possible with WebDriver.

The [hidden] part of my question .. bonus if you know, but not required. :-)

And also, I don't even need to see this browser window, so I'd prefer that it's hidden. Does the browser need to be seen or can I do the webdriver tests without having the task/browser open in Windows?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Yes, you can interact with a window that is spawned as part of the automated test with this code:

void startSelenium() { driver_ = new FirefoxDriver(); selenium_ = new WebDriverBackedSelenium(driver_, "https://....com"); }

   // go to last window handle in list = the one launched by the login click
   for (String handle : driver_.getWindowHandles()) {
       System.out.println("win " + handle);
       driver_.switchTo().window(handle);
       System.out.println("href: " + selenium_.getLocation());
   }

I haven't tested this code, I got it from this page along with additional info: http://osdir.com/ml/selenium-users/2011-04/msg00440.html

For the second question about a hidden browser, I would suggest using the HTMLUnit driver. This would also solve any issues with simultaneous interaction with both windows.

share|improve this answer
    
I'll accept once I write the C# code for this and get it working –  MacGyver Feb 24 '12 at 23:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.