Handing Window,Frames,IFrames

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

WebDriver

defaultContent()

Selects either the first frame on the page, or the main document when a page contains iframes.

WebDriver

frame(int index)

Select a frame by its (zero-based) index.

WebDriver

frame(java.lang.String nameOrId)

Select a frame by its name or ID.

WebDriver

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:

  1. Access the website URL www.rediff.com
  2. Enter the Stock Name TCS and click on ‘Get Quote’ button which opens the new Window for displaying the Stock price of TCS.
  3. Handling Windows

  4. Ensure the New window opens displays the Stock price of TCS.
  5. Handling Windows

  6. Execute the Selenium Webdriver Script and retrieve the price and display in the console.



Leave a Reply

Your email address will not be published. Required fields are marked *