There will be several occasions while automating a web application where we need to move our control to the next tab.
This may occur if the link is opened in a new tab or if the pop-up is opened as a new tab etc.
But if we don't know the title of the new tab, we can't easily switch to the new tab and do WebDriver actions there.
Below is a simple code to switch tabs in the browser using selenium with only the index number of the tab.
Once we are switched to a new tab, we can get the tab title from there which can be used in further steps of the test.
/// <summary> /// Method to change focus to first child window /// </summary> public void switchFocusToNextWindow() { driver.SwitchTo().Window(driver.WindowHandles.ElementAt(1)); Console.WriteLine("Focus changed to new window with name as " + driver.Title); }
No comments:
Post a Comment