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());
We use Explicit wait as WebDriverWait wait = new WebDriverWait(driver,10) ; and wait. until(ExpectedCondition. alertIsPresent()); If the alert is present, then we will accept it using driver.
Explicit Wait in SeleniumBy using the Explicit Wait command, the WebDriver is directed to wait until a certain condition occurs before proceeding with executing the code. Setting Explicit Wait is important in cases where there are certain elements that naturally take more time to load.
The Implicit Wait in Selenium is used to tell the web driver to wait for a certain amount of time before it throws a “No Such Element Exception”. The default setting is 0. Once we set the time, the web driver will wait for the element for that time before throwing an exception.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With