Saturday, April 25, 2020

How to Handle Alert PopUp In Selenium

package com.seleniumpractice;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class AltertDemo {

public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Users\\admin\\Desktop\\Selenium_software\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://artoftesting.com/sampleSiteForSelenium");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
WebElement ele=driver.findElement(By.id("dblClkBtn"));
Actions act=new Actions(driver);
act.doubleClick(ele).perform();
Alert alt=driver.switchTo().alert();
Thread.sleep(2000);
String actualstr=alt.getText();
System.out.println("String value..."+actualstr);
String expStr="Hi! Art Of Testing, Here!";
if(actualstr.equals(expStr)){
alt.accept();
System.out.println("Test case pased");
}
else {
System.out.println("Test case failed");
}
//alt.accept();
//driver.close();

}

}
========================================================================

No comments:

Post a Comment

Q) How To Find Duplicate Characters In A String In Java?

Step1:- Creating a HashMap containing char as key and it's occurrences as value. Step2:- Converting given string to char array. Step3:- ...