如何使用 Selenium WebDriver 在 Chrome 中激活 AdBlocker? [英] How to Activate AdBlocker in Chrome using Selenium WebDriver?

查看:28
本文介绍了如何使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆