How to Activate AdBlocker in Chrome using Selenium WebDriver?

后端 未结 1 1854
醉话见心
醉话见心 2020-12-30 15:33

I would like to activate Adblocker for Chrome with Selenium WebDriver Java.

How can it be done?

相关标签:
1条回答
  • 2020-12-30 16:00

    You can either use the crx file of the extension or point to a directory it's installed in. Assuming you have it installed, you'll need to add ChromeOptions to your new ChromeDriver:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("load-extension=/path/to/extension");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    ChromeDriver driver = new ChromeDriver(capabilities);
    

    See here for more details and walkthrough.

    EDIT: to see your extensions path, navigate to chrome://version and look at 'Profile Path'. In that folder look for 'Extensions' folder. The extension ID for AdBlock Plus is cfhdojbkjhnklbpkdaibdccddilifddb. So the path/to/extension should be something like (Windows):

    C:\Users\<user>\AppData\Local\Google\Chrome\User Data\<profile>\Extensions\cfhdojbkjhnklbpkdaibdccddilifddb
    
    0 讨论(0)
提交回复
热议问题