CoolRon
CoolRon

Reputation: 1

Handling custom pop-ups (not the default windows one) through selenium webdriver (3.x)

I want to automate a scenario.

When the browser lands on the website, there is a warning pop-up that requires a response to the prompt: Do you want to proceed?

There are two options Leave and Continue.

I am trying to switch the control with the following functions but its not working.

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

Upvotes: 0

Views: 1065

Answers (1)

Akbar
Akbar

Reputation: 45

If its JavaScript alert, then driver.switchTo().alert().accept(); should work by accepting the default. Is this pop-up or modal window? Did you try to switch to window and click on the button? Also, which browser are you using? JavaScript alert might needs to handled differently based on the browser. If its modal or window, then getWindowHandle() should work fine.

String newWindow = driver.getWindowHandle();
driver.switchTo().window(newWindow);
//Switching to new window
driver.findElement(By.id("buttonId"));
//Switching back to default/main window
driver.switchTo().defaultContent();

Upvotes: 1

Related Questions