HANDLING WINDOWS/IFRAMES:
In order to handle windows/browsers in selenium, WebDriver API contains following methods which helps the user to switch between windows.
API Url–> https://seleniumhq.github.io/selenium/docs/api/java/
org.openqa.selenium
Interface WebDriver.TargetLocator
defaultContent() Selects either the first frame on the page, or the main document when a page contains iframes. |
|
frame(int index) Select a frame by its (zero-based) index. |
|
frame(java.lang.String nameOrId) Select a frame by its name or ID. |
|
window(java.lang.String nameOrHandle) Switch the focus of future commands for this driver to the window with the given name/handle. |
org.openqa.selenium
Interface WebDriver
java.lang.String |
getWindowHandle() Return an opaque handle to this window that uniquely identifies it within this driver instance. |
java.util.Set<java.lang.String> |
getWindowHandles() Return a set of window handles which can be used to iterate over all open windows of this WebDriver instance by passing them to switchTo().WebDriver.Options.window() |
Please find the usage of API methods in the following example:
- Access the website URL www.rediff.com
- Enter the Stock Name TCS and click on ‘Get Quote’ button which opens the new Window for displaying the Stock price of TCS.
- Ensure the New window opens displays the Stock price of TCS.
- Execute the Selenium Webdriver Script and retrieve the price and display in the console.