Search code examples
javaseleniumframe

How to Handle Pop Up IFrame Window In Selenium


I am new in Slenium. enter image description here

I am trying to handle the pop-up Form.

When I click in New Button the pop-up form like this will open. enter image description here

I try the handle this by alert(), pop up handling and also by Child Browser Handling. But didn't get the solution. Please suggest some solution for this issue


Solution

  • If it's an <iframe> element then you need to switch WebDriver to this frame in order to work with it. Here's an example of how you can do this:

    By locIframe = By.xpath("//iframe[@name='popup']");
    driver.switchTo().frame(driver.findElement(locIframe));
    // driver is an instance of RemoteWebDriver
    

    The Xpath locator is just an example: you need to write your own here. Also you can use any other locator to find that <iframe> element in the page source.

    After switching to iframe element WebDriver will see it's page source and will be able to work with it.