10

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

How can it be done?

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176

1 Answers1

6

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
Moshisho
  • 2,781
  • 1
  • 23
  • 39
  • unable to find the path of plug in(CRX), where it is actually loacted? – sameer joshi Feb 16 '17 at 06:13
  • There are many folders in 'Extensions' folder. How can I identify the extension ID for AdBlock Plus? – Ripon Al Wasim May 14 '18 at 10:48
  • In my case I didn't find the ID on Chrome (version 69.0.3497.100) so I had to use the extension version and check on each folder (not the best way but can works for anyone) – mauronet Sep 20 '18 at 14:43
  • Thanks, I needed a crx file too, I zipped the extension (.crx is a simple zip fle) and it worked right away. https://chrome-extension-downloader.com/ works too. – wteuber Nov 27 '19 at 08:41