Selenium automated testing: workaround when encountering pop-ups

March 3rd, 2017 by George Codreanu in Automated testing

StockSnap_8B0Z5GDJT1During the runtime of our automated testing scripts, a common problem that blocks the completion of the tests arises from the appearance of pop-ups that are displayed for a small amount of time. This kind of situations can be easily missed when writing the test script, due to their short display time.


An example of such a pop-up for the automated testing of a Magento based e-commerce website:

Automated Testing

In the case above, the popup will appear for a short time when trying to search for a product in the database. While this popup is displayed, the rest of the page will not be clickable. This is problematic if you use the click() method for an element, immediately after searching for a product. The test script will fail with the bellow error:

org.openqa.selenium.WebDriverException: unknown error: Element < The element that should be clicked>…</a> is not clickable at point (m, n). Another element would receive the click: <”The pop-up that is displayed”>…</div>

As stated in the above error, the element that should be clicked is not available due to the pop-up being displayed.

In order to address this problem there are 2 methods:

The inefficient one

One workaround for this problem is to set an implicit wait. You specifically make the test script wait for a given amount of time. So if the pop-up lasts for 2-3 seconds, you can give it an appropriate wait time.

driver.manage().timeouts().implicitlyWait(amountOftime, time unit);

This is not recommended, as it is not efficient. On the machine on which the test scripts are developed, the script may work ok, but when deployed on another machine (i.e. a test server) in an environment where the internet bandwidth is smaller, this test script will most likely fail.
Also if you have multiple implicit waits, the total test script duration will be affected. For these reasons, this method should be avoided.

The scalable one

The best way is to wait the exact amount of time for such a popup to disappear. This can be done by checking if the popup is still displayed on the screen and when it’s not, to click the element needed.

This can be easily done with a while loop:


The loop will run until the condition is no longer respected, meaning as soon as the popup is no longer displayed, the loop will end and the script will move on to the next statements.

It’s a simple and efficient way which doesn’t load the script with useless waiting time.

You can also define methods that can be used in these scenarios.

public static int longWait = 50;
public static WebElement clickable(WebDriver driver, By locator) {
             return new WebDriverWait(driver, longWait).until(ExpectedConditions.elementToBeClickable(locator));

This method waits until an element is clickable.

Our QA team provides automated testing by using frameworks, such as Selenium, to create test scripts, while simulating the user interactions on various browsers, such as: Chrome, IExplorer, Firefox. Our team members are ISTQB certified and have tested over 300 solutions. Just say for a free consulting meeting.


DZoneGoogle ReaderYahoo MessengerRedditEmailDelicious

You might also like

Dynamically create Spring beans from groovy scripts at runtime In the current project - a java based CMS - we were faced with an interesting problem: how can we...
Create and populate your database independent of the db server using ant, dbunit and hibernate Database creation is such a common task that you must have some scripts and tips and tricks at hand,...
Javascript advanced tutorial I prepared a quick Javascript tutorial during the weekend and presented it to my colleagues in Tremend....
Develop with pleasure – IntelliJ Idea 6.0 Beta IntelliJ's Idea 6.0 Beta is out and available free for evaluation. Most expected features were GWT support,...

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.