How to find and close particular browser window from number of opened windows using Selenium?



  • Suppose there are five Browser windows opened, how to find the third one and close it through web driver? Please I'm request you to all of you don't consider this question as a opinion based. I have this situation while working with my current project. There are number of windows gets opened while performing purchase section activity.

    I have to close selected number of windows. What should I do using WebDriver?



  • You can use the below code:

    List handles = (List) driver.getWindowHandles();
    // Switch to the third window.
    driver.switchTo().window(handles .get(2));
    // Close this window
    driver.close()
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2