How to Activate AdBlocker in Chrome using Selenium WebDriver?
11,303
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
Author by
Admin
Updated on June 05, 2022Comments
-
Admin almost 2 years
I would like to activate Adblocker for Chrome with Selenium WebDriver Java.
How can it be done?
-
sameer joshi about 7 yearsunable to find the path of plug in(CRX), where it is actually loacted?
-
Ripon Al Wasim almost 6 yearsThere are many folders in 'Extensions' folder. How can I identify the extension ID for AdBlock Plus?
-
mauronet over 5 yearsIn 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)
-
knugie over 4 yearsThanks, I needed a crx file too, I zipped the extension (.crx is a simple zip fle) and it worked right away. chrome-extension-downloader.com works too.