7

I am pressing a cancel button than according to my code it is checking some text. In Chrome and Firefox it is working fine but in IE it is taking time to perform operation on alert box but code moves to next line.

So i want some code that stop till the operation is preformed on alert box and than it goes to next Step. I am doing automation testing using selenium.

Please find piece of code:

Alert al = driver.switchTo().alert();
al.accept();

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='content-body-full']/p[1]")));
assertEquals("Your cancellation request has been successfully executed.",driver.findElement(By.xpath(".//*[@id='content-body-full']/p[1]")).getText().toString());
Cœur
  • 37,241
  • 25
  • 195
  • 267
OPTIMUS
  • 672
  • 4
  • 14
  • 29

1 Answers1

16

You want to wait until the alert is present before switching to it, similar to your 3rd row. Reference.

EDIT: try:

new WebDriverWait(driver, 60)
        .ignoring(NoAlertPresentException.class)
        .until(ExpectedConditions.alertIsPresent());

Alert al = driver.switchTo().alert();
al.accept();
Erki M.
  • 5,022
  • 1
  • 48
  • 74
  • In this code first line is switching to alert box and second line is pressing ok button. Than it is checking some element. I want that it must move to next line only and only if ok button of alert is pressed – OPTIMUS Apr 14 '14 at 06:40
  • Do you have any idea about this http://stackoverflow.com/questions/23053632/is-xpath-is-different-for-different-browser – OPTIMUS Apr 14 '14 at 06:50
  • Thank you! Exactly what I was looking for. Local variable for alert seems redundant - instead: driver.switchTo().alert().accept(); – Grzech Apr 01 '22 at 09:16