Selenium webdriver selecting new window c#

jim7 picture jim7 · Mar 13, 2015 · Viewed 37.9k times · Source

Trying to write some test cases using selenium webdriver in c# and have a scenario which i'm unsure of how to resolve

user scenario is searching a table for a patient, select a patient then a new window opens and then assert various items on the window

my issue is i'm unable to select the new window to assert anything from, it's not a pop-up window, it's a full new browser window but it has no window title/name to identify it by, how would I be able to switch driver focus to this window?

thanks in advance

Answer

joinsaad picture joinsaad · Mar 13, 2015

It is really easy in Selenium WebDriver. By using SwitchTo method

driver.SwitchTo().Window(driver.WindowHandles.Last());

See this blog post as well

http://binaryclips.com/2015/03/13/selenium-webdriver-in-c-switch-to-new-window/