简体   繁体   中英

How to handle a pop up which is a simple HTML pop up in selenium webdriver?

How to handle a pop up which is a simple HTML pop up in selenium webdriver . Its a pop up written in HTML .

Have you tried using

driver.switchTo().alert().accept();

?

In case the pop up is modal you have to do what the previous answer is proposing, but in case the pop up is just HTML you should just find a WebElement inside the popup code and work as usual, look the example:

driver.findElement(By.id(popupid))

Pay attention and manage the implicit timeout in order to make sure the find will wait until the popup starts.

Use below given sample code and it will work.

public String parentWindowHandler = null,subWindowHandler=null;
    Set<String> handles = driver.getWindowHandles(); // get all window handles
    Iterator<String> iterator = handles.iterator();
    while(iterator.hasNext()){
    subWindowHandler = iterator.next();
    driver.switchTo().window(subWindowHandler);//select new popup
    }


    /*
    your code here for script

    */

    driver.switchTo().window(parentWindowHandler);//return to main window

First, you should find unique DOM properties because of sometimes same element properties like id and class same for HTML pop-up and parent Page.

So If it's unique then u can perform simply drive.findelements(By).click() , or sendkeys(), etc else u should be made unique XPath or by indexing, u have to click or perform other action.

SwitchTo uses if it is in iframe else it will not use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM