setUnhandledPromptBehaviour in Selenium
setUnhandledPromptBehaviour methods helps the user to handle the un
handled alert. Whenever there is an alert this method performs operation on
that based on your input to this method.
Note: With few versions this method may not work.
Note: With few versions this method may not work.
package
pack2;
import
org.openqa.selenium.By;
import
org.openqa.selenium.UnexpectedAlertBehaviour;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.chrome.ChromeDriver;
import
org.openqa.selenium.chrome.ChromeOptions;
public class
ChromeOptionsEx
{
public static void
main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\PATH\\chromedriver.exe");
ChromeOptions fo = new
ChromeOptions();
//
set the behaviuor of the alert
fo.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.ACCEPT);
//
create object to firefox driver, register options class
WebDriver driver = new
ChromeDriver(fo);
driver.get("https://www.pop-ups-selenium-webdriver.com");
driver.findElement(By.name("alert")).click();
driver.findElement(By.name("prompt")).click();
}
}
No comments:
Post a Comment