1

Currently I am working on a e-commerce website. When I visit the site for first time they are displaying a popup, like discounts or signup etc... while writing my scripts I wrote code for waiting for the popup and closing the popup. But after some days the developers removed the popup ad's. So now my script is failing too find the popup as per coding. How can I handle such a scenario?

0

you can write a code to find out if pop is present or not, based on that follow the next steps. your code may look like this.

public boolean popupPresent(driver) {
boolean foundElement = false;
try {
    WebDriverWait wait = new WebDriverWait(driver, 20);
    // here your code for finding out the popup
     foundElement = true;
    }
    catch(Exception error) {
    foundElement = false;
    }
    return foundElement;
    }

Then call this function and perform the action.

boolean popupPresent = popupPresent(driver);

if(popupPresent) {
// code to close your popup.
}
  • Hi @Jeevan Bhushetty, thats a good idea.But I am using Expected wait conditions when ever it is not met with expected condition it is throwing an Timedout exception.How to handle that ??? – QAMember Mar 4 '16 at 8:04
  • @QAMember thats how my code works, after WebDriverWait wait = new WebDriverWait(driver, 20); write your expected wait condition, It will check for 20 secs if not found the exception will caught in catch block and set values of foundElement to false and function will return false value. This way you can catch the exception and mark it as element not found and you test case continues – Jeevan Bhushetty Mar 4 '16 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.