Türkiyenin en kapsamlı forum/yorum portalı olacak olan sitemize katkıda bulunmak ister misiniz? Moderatorler/Yöneticiler aramaktayız. BİZE YAZIN >>

How to handle 2 alert in Selenium WebDriver

markblake
Mesaj: 134

How to handle 2 alert in Selenium WebDriver

Mesaj#1 » 2017 Ağu 01 10:20

0
down vote
favorite
I have an automation scenario to perform a content searching. The problem happen in the search result screen where there are 2 Javascript alert popup appears at nearly the same time. I said nearly because the popup window appears one by one, not all of them at once. I managed to handle the first one, but not with the second one. NoAlertPresentException happened for the second alert handler code.

Here's where the alert happened:

public WSSPage enterAndSearchContent(String title) {
waitWSSPageLoaded();
waitForElementTextWithEnter(searchTextField, title);
waitWSSPageLoaded();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.dismiss();
wait.until(ExpectedConditions.alertIsPresent()); //NoAlertPresentException happened here
Alert alert2 = driver.switchTo().alert();
alert2.dismiss();
return PageFactory.initElements(driver, WSSPage.class);
}
I alse tried using alert.dismiss(); twice but still it gives NoAlertPresentException at the second alert.dismiss(); like the below code:

public WSSPage enterAndSearchContent(String title) {
waitWSSPageLoaded();
waitForElementTextWithEnter(searchTextField, title);
waitWSSPageLoaded();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.dismiss();
alert.dismiss(); //NoAlertPresentException happened here
return PageFactory.initElements(driver, WSSPage.class);
}
When I try manually dismissing the alert, the second alert appears almost instantly. I guess the problem is the code can't catch the second alert because it was too fast? Is there any workaround for this problem?

Please help...

I didn't find the right solution from the Internet.
References
https://stackoverflow.com/questions/454 ... -webdriver
Industrial Equipment Video

“Araçlar” sayfasına dön

Kimler çevrimiçi

Bu forumu görüntüleyen kullanıcılar: Hiç bir kayıtlı kullanıcı yok ve 0 misafir

cron

Giriş  •  Kayıt