I am getting random (Google) ads (banners) while automating the App test. The ads are covering the full screen of the device and there is one cross-mark at the top of the ad to close it.

I tried

autoacceptalert, false

to close the ad but its not working.

Any suggestions will be appreciated.

  • Have you installed ad-blocker(s) on the device?
    – Dave M
    Apr 4, 2016 at 12:33
  • thank you for your reply adblocker works for safari browser not in the apps i guess,i have a particular app when we open the app google ads are coming randomly any suggestions
    – Hari
    Apr 5, 2016 at 8:58
  • @Hari, is there no way to turn off the ads from the app itself? Such as buying it. Apr 6, 2016 at 14:35

1 Answer 1


First option you have is to ask your developers to create a version of the application without ads.

Advantages - No ads.

Disadvantages - You will not be testing the exact same code as you plan to release.

You can disable only fullscreen ad.

I think there is no best way to do this. Stable automate checks or checking the exact same code as you plan to release.

Second option is to catch if ad is visible, and press back button.

For example (example fo Android):

protected boolean checkAdvert(AppiumDriver<WebElement> driver, int timeout) {
    By adTree = By.xpath("//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]");
    Map<String, Object> adParams = new HashMap<>();
    //trying to wait for the ad to come up and then click the Expense button
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    FluentWait<WebDriver> await = new FluentWait<WebDriver> (driver)
            .withTimeout(timeout, TimeUnit.SECONDS)
            .pollingEvery(500, TimeUnit.MILLISECONDS)
    try {
        await.until (ExpectedConditions.visibilityOf(driver.findElement(adTree)));
        // go BACK to eliminate the popup
        adParams.put("keySequence", "BACK");
        driver.executeScript("mobile:presskey", adParams);
        System.out.println("Press the back button to get out of ad");
        return true;
    } catch (Exception t) {
        System.out.println("no ad showed up");
        return false;

and use this in page object class:

public void addExp(String desc, String amount) {
    do {
        try  {
            adClick = false;
        } catch (NoSuchElementException ne) {
            adClick = checkAdvert(driver, 1);
            if (!adClick) throw ne;
    } while (adClick);

Source: Dismiss a popup advertisement while automating an app

But you must remember that ads may be different, you can try to find universal selector. But I think it will hard to cover all cases.

adTree = By.xpath("//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]");
  • @Kate Paulk♦ You can disable only fullscreen ad. I think there is no best way to do this. Stable automate checks or checking the exact same code as you plan to release. Feb 14, 2017 at 15:08
  • Or You can try something like this Dismiss a popup advertisement while automating an app, but I think it will not cover all cases. Feb 14, 2017 at 15:18
  • Could you please edit the answer to add that information - but please explain what is in the link so the information isn't lost if that page ever goes away. If you have any affiliation with the site, you will need to disclose that as well.
    – Kate Paulk
    Feb 14, 2017 at 18:04
  • @KatePaulk done, I hope that this is enough :) Feb 14, 2017 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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