package selenium_examples;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample {
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.rediff.com");
driver.findElement(By.linkText("Sign in")).click();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.findElement(By.id("btn_login")).click();
Alert alt=driver.switchTo().alert();
System.out.println(alt.getText());
alt.accept();
}
}
Output:-
Please enter your email ID
Alert alt=driver.switchTo().alert();->Get a handle to the open alert, prompt or confirmation
alt.getText()->Gets the text of alert
alt.accept()->To Accept any alert, i.e Clicking OK button
alt.dismiss()->To dismiss any alert, i.e Clicking Cancel button
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample {
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.rediff.com");
driver.findElement(By.linkText("Sign in")).click();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.findElement(By.id("btn_login")).click();
Alert alt=driver.switchTo().alert();
System.out.println(alt.getText());
alt.accept();
}
}
Output:-
Please enter your email ID
Alert alt=driver.switchTo().alert();->Get a handle to the open alert, prompt or confirmation
alt.getText()->Gets the text of alert
alt.accept()->To Accept any alert, i.e Clicking OK button
alt.dismiss()->To dismiss any alert, i.e Clicking Cancel button
No comments:
Post a Comment