Search code examples
c#seleniumselenium-webdriverwebdriverpopupwindow

Selenium webdriver selecting new window c#


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


Solution

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

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

    See this blog post as well

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