Martin Mussmann
Martin Mussmann

Reputation: 687

How to control browser in focus?

I'm playing around with C# webdriver and trying to figure out how to control which browser is in focus.

This is basicly what i want do

        driver = StartBrowser();
        driver1 = StartBrowser();

and then switch back to driver, but i can't get it working.

I know it's prob really simple but i still can't get it working :).

This is what i tried different versions of:

driver.SwitchTo().Window(driver.CurrentWindowHandle);

Upvotes: 1

Views: 890

Answers (1)

prestomanifesto
prestomanifesto

Reputation: 12796

SwitchTo is to change the context of a single driver (browser). This is used when you have frames or pop up windows and you want to tell selenium where to look for elements.

If you declare two separate driver instances (per your example) then you will have two independent browser instances where each will have its own context to search. There is logically no reason to switch between them because you can search each browser by using the corresponding driver variable.

Upvotes: 1

Related Questions