how to hadle pop-up or alert

Hi All, From last two days i am try to handle one alert box but still i am not able to click on ok button.Can any one help me.I am tri

how to hadle pop-up or alert

ed in several ways.
method 1:
/* // waiting for error box alert
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“PopupMsgBox”)));

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//*[@id=’PopupMsgFooter’]/a”)));
driver.findElement(By.xpath(“//*[@id=’PopupMsgFooter’]/a”)).click();
Alert alert=driver.switchTo().alert();
System.out.println(alert.getText());
alert.accept();*/
method 2:

for(;;){

try{
wait2.until(ExpectedConditions.visibilityOfElementLocated(By.linkText(“OK”)));
driver.findElement(By.linkText(“OK”)).click();
break;
}
catch (Exception e){

wait2.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//*[@id=’WIN_3_301389614′]/div[2]/div/div[2]”)));

}
}

Default Asked on August 14, 2016 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    Srinivasarao, Can you share the relevant part of the HTML. I suggest following
    – Put wait just after driver.findElement(By.xpath(“//*[@id=’PopupMsgFooter’]/a”)).click();  this statement and before doing a switch.
    – If the above step doesnt, can you try to see any IFrame in the HTML hierarchy that can cause problems.

    Virender

    Professor Answered on August 16, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.