How to handle intermittent Pop-up

Hi All,

I am facing a issue about intermittent pop-up. when i click on a button, there is a pop-up appeared. then we can use “$browser.switchTo().alert().accept();” to accept the alert. after that the expected page will exist. however sometimes there is no such pop-up, so the expected page can be displayed directly. do you know is there any way to check if the alert is appeared? BTW, for that kind of Pop-up, we cannot to check the HTML code. since if the pop-up is displayed, it prevent us from doing anything except for accepting it. please find my part of script as below:

// Step 178
.then(function() {
log(178, ‘clickElement “//li//a[text()=‘Next’]”’);
return $browser.waitForAndFindElement(By.xpath("//li//a[text()=‘Next’]"), DefaultTimeout); })
.then(function (el) { el.click(); })

// Step 179
.then(function() {
log(179, ‘$browser.switchTo().alert().accept()’);
return $browser.switchTo().alert().accept(); })

// Step 180
.then(function () {
log(180, ‘waitForElementPresent “//div[contains(text(),‘Price discount’)]”’);
$browser.wait(function () {
return $browser.isElementPresent(By.xpath("//div[contains(text(),‘Price discount’)]")).then(function (bool) { return bool; });
}, DefaultTimeout);
})

if you have any idea to handle this kind of problem, much appreciated.

Hi @steven.xu: This is a common question and has various answers:
Trouble with Pop-up
Pop-up Handling
Pop-up Windows
Interacting (and closing) pop up windows

Forum mods: I think it would be useful to provide some solution in the documentation or post a sticky as this seems to be a fairly common question.

Anyone can point me to the right direction to script a website FaceBook Login on New Relic?

Following is the closest that i can find, any advice to translate it to New Relic Script?

Thanks!

@fred2016 I am going to let the community jump on your request—that is a bit out of our realm but I am interested in what you find out! Feel free to report back here and share your success! :blush:

Hi @stefan_garnham,

thanks a lot for your response. i am finding a way to handle the intermittent Pop-up without conditional check for an element. for those topics you’ve suggested i have already checked. however in my case, i cannot get the HTML code of pop-up. so cannot use the conditional check for an element.

Hi @steven.xu,
were you able to find the solution for the issue you mentioned as we are finding the same issue and cannot get the html code and popup comes up intermittently throwing the alerts.