如何使用Selenium WebDriver在Chrome中激活AdBlocker? [英] How to Activate AdBlocker in Chrome using Selenium WebDriver?
问题描述
我想使用Selenium WebDriver Java激活Chrome的Adblocker.
I would like to activate Adblocker for Chrome with Selenium WebDriver Java.
怎么办?
推荐答案
您可以使用扩展的crx文件,也可以指向扩展的安装目录.假设已安装,则需要添加new ChromeDriver
:
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.
要查看您的扩展程序路径,请导航至chrome://version
并查看配置文件路径".在该文件夹中查找扩展名"文件夹. AdBlock Plus的扩展名ID为cfhdojbkjhnklbpkdaibdccddilifddb
.因此,路径/到/扩展名应该类似于(Windows):
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
这篇关于如何使用Selenium WebDriver在Chrome中激活AdBlocker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!