How to Activate AdBlocker in Chrome using Selenium WebDriver?(如何使用 Selenium WebDriver 在 Chrome 中激活 AdBlocker?)
问题描述
我想用 Selenium WebDriver Java 激活 Adblocker for Chrome.
I would like to activate Adblocker for Chrome with Selenium WebDriver Java.
怎么做?
推荐答案
你可以使用扩展的 crx 文件或者指向它的安装目录.假设你已经安装了它,你需要添加 ChromeOptions 到你的 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>AppDataLocalGoogleChromeUser Data<profile>Extensionscfhdojbkjhnklbpkdaibdccddilifddb
这篇关于如何使用 Selenium WebDriver 在 Chrome 中激活 AdBlocker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Selenium WebDriver 在 Chrome 中激活 AdBlocker?
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
