Search code examples
google-chromeselenium-webdrivergoogle-chrome-extensionselenium-chromedriverrobotframework

Disable Google Vignette ads on Chrome


I'm currently working on website automation using Robot Framework and Selenium. The problem is that the Google Vignette ads always come up, and that makes my test case fail. Do you guys have any solutions to this problem?

By the way, I also tried to add this option, but it still doesn't work.

Open Browser https://automationexercise.com browser=chrome options=add_argument("--disable-popup-blocking")

Solution

  • I have block ads form product page using JavaScript executor

    1. Google Vignette ads on "https://automationexercise.com" if user try manually he can see the google ads

    following working code

    public class googleAdsblock {
    
             static WebDriver driver;
                
             
            @Test
            public static void blockads() throws InterruptedException{
                    System.setProperty("webdriver.chrome.driver", "C:\\bin\\chromedriver.exe");
                    driver = new ChromeDriver();
                    driver.get("https://automationexercise.com");
                    WebElement productBtn = driver.findElement(By.xpath("//i[@class='material-icons card_travel']"));
                    productBtn.click();
                    Thread.sleep(1000);
                    
                 
                    JavascriptExecutor js = (JavascriptExecutor) driver;
                    
                     
                 //blocking google ads
                    js.executeScript("const elements = document.getElementsByClassName('adsbygoogle adsbygoogle-noablate'); while (elements.length > 0) elements[0].remove()");
                 
                    js.executeScript("window.scrollBy(0,350)");
                    driver.findElement(By.xpath("//a[@href='/product_details/1']")).click();
                    driver.close();
             }
    }
    

    blogger link for more details link