Introducing the switchTo() method

Selenium has to be explicitly told which window to focus on. In this case, it has focused on the first parent window. We switch windows in Selenium using the switchTo() command, which is invoked on the driver object. The signature of switchTo is driver.switchTo.window(String). The switchTo() method is in the WebDriver interface, which returns an object of the TargetLocator interface: a child interface of WebDriver. On this object of TargetLocator, the window method is invoked and this returns a WebDriver object. The parameter is of a string type, which is the alpha-numeric handle of the window. Let's handle the small issue in our code by adding switchTo().window(String) at two places in our code right after extracting the window handles for parent and child windows. The string parameters will be parent and child.

The output After this addition is shown here:


No of open windows: 2
Parent Window: CDwindow-3378E656C226EBA5B5880A0DE93D1E24title: PopupTest - test your popup killer software
Child Window:CDwindow-76B76D2A879C440BBC8A548230320459title: PopupTest Sunday August, 19 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.191.22