Monday, 23 May 2022

How To Handle Javascript Alert in Selenium Webdriver using Java | Selenium Javascript Alert Ok

                    In this post, we will see How To Handle Javascript Alert in Selenium Webdriver using Java | Selenium Javascript Alert Ok 


Program Code:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class Alert {


public static void main(String[] args) 

{

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_confirm");

driver.manage().window().maximize();

WebElement w=driver.findElement(By.xpath("//iframe[@id='iframeResult']"));

driver.switchTo().frame(w);

//click try button

driver.findElement(By.xpath("//button[@onclick='myFunction()']")).click();

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

driver.switchTo().alert().dismiss();


}


}  


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=ezkwV8nSvcg&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=12

No comments:

Post a Comment