July 12, 2016

Perfect Example for Handling Window,popup,Frame and Alerts

In this post i will explain about how to handle

  1. Multiple windows
  2. Popups
  3. Tabs
  4. Frames
  5. Alerts
and how to write customized functions, instead of duplicating the webdriver code.

Here is one example to switchToChildWindow()
This method is useful to switch to new window/tab/popup if you have only 2 windows/tabs/popup then you can use below customized function.



In the below example i wrote different functions 

  1.  isElepresent(By locator) -- Verify if the element is present or not
  2. selectByText(By locator, String visibleText) select a value from dropdown
  3. switchToChildWindow() ---Switch to  child window. If there are only two windows.
  4. switchToWindowByTitle(String title)  ---Switch to child window. Use this if title of the pages are unique.
  5. switchToFrame(WebElement locator)  --switch to frame by locating the frame.


Scenario: which has all multiple windows/tabs/popups/alerts/frames etc...

  1. Open http://www.hdfcbank.com/
  2. Close the Ad window if that is visible
  3. Click on Agri Link --which will open new window/tab
  4. Select "Telugu" from dropdown
  5. Handle the alert
  6. Select "English" from dropdown
  7. Click on Account Details --which will open new window/tab
  8. In the new window, enter customer ID --"test" (Actually this text box is in frame)
  9. Click on Privacy Policy link (Actually this link is in another frame) --which opens new window/tab/popup
  10. Click on CSR link on Privacy Policy page.
  11. Now come back to Main window (Parent window) 
  12. Click on Customer Care.

Below is the code:







8 comments:

  1. Useful post.Thanks for sharing that information. I believe there are many more pleasurable opportunities ahead for Individuals that looked at your site. If you want to Get more Vendor Reconciliation | Fixed Assets Audit
    Visibility Audit

    ReplyDelete
  2. Amazing post. Keep it up. Much thanks to you such an incredible sum for sharing your beneficial blog.
    Duplicate Payment Audit
    AP Vendor Helpdesk
    Continuous Transaction Monitoring

    ReplyDelete
  3. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.Duplicate Payment Audit
    Continuous Monitoring
    Duplicate Payment

    ReplyDelete

  4. شركة تسليك مجارى الكويت شركة تسليك مجارى بالكويت
    سباك الكويت سباك بالكويت
    شركة تنظيف الكويت شركة تنظيف بالكويت

    ReplyDelete
  5. Taking selenium classes is a rage these days. Furthermore, this web-based, open source automation framework has successfully made a place for itself in the IT market. In spite of the fact that you can approach any institute for selenium training in Gurgaon, APTRON Gurgaon has no match in this regard. APTRON Gurgaon happens to be one of those institutes that believe in offering best selenium training in Gurgaon. In this way, don't make any delays, and get enrolled today.

    For More Info: Selenium Course in Gurgaon

    ReplyDelete