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?
基础教程推荐
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
