We are not able to inspect the alerts and some popups in the browsers.
In such cases we have to switch the focus from the screen to the pop up. For
switching there is a ‘Switch’ option available in selenium.
Example:
System.setProperty("webdriver.chrome.driver",
"./drivers/chromedriver.exe");
WebDriver driver=new
ChromeDriver();
Alert or popup handling
driver.get("https://mail.rediff.com/cgi-bin/login.cgi");
driver.findElement(By.xpath("//input[@type='submit']")).click();
Alert alertbox=driver.switchTo().alert();
String alertMessage=alertbox.getText();
System.out.println(alertMessage);
Assert.assertEquals("Please enter a valid user
name", alertMessage);
driver.switchTo().alert().accept();
driver.switchTo().alert().dismiss();
driver.switchTo().alert().getText();
driver.switchTo().alert().sendKeys(keysToSend);
driver.switchTo().alert().dismiss();
driver.switchTo().alert().getText();
driver.switchTo().alert().sendKeys(keysToSend);
No comments:
Post a Comment