How to Activate AdBlocker in Chrome using Selenium WebDriver?

♀尐吖头ヾ 提交于 2019-11-29 15:43:34

问题


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

How can it be done?


回答1:


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


来源:https://stackoverflow.com/questions/42231604/how-to-activate-adblocker-in-chrome-using-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!