October 2018
Intermediate to advanced
192 pages
5h 12m
English
We have created a sample HTML page with a textbox and button. When the Display Alert button is clicked, the modal alert is displayed with OK and Cancel buttons. At this point, the textbox on the main page cannot be accessed. When the OK or Cancel buttons are clicked, an appropriate message is displayed on the main page.
The following code will click on the Display Alert button and later will click once on the Ok button of the modal alert, and the next time will click on the Cancel button:
WebDriver driver = new ChromeDriver(); driver.navigate().to( "C:\\modalalert.html"); driver.findElement(By.id("dispalert")).click(); Alert alert = driver.switchTo().alert(); alert.accept(); driver.findElement(By.id("text1")).sendKeys("Ok ...Read now
Unlock full access