如何禁用硒中的铬扩展 [英] how to disable chrome extension in selenium

查看:121
本文介绍了如何禁用硒中的铬扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在启动我的硒铬时禁用所有的Chrome扩展。
但是每次运行代码时,所有扩展都会继续启动。
是否有禁用扩展的方法。

I am trying to disable all chrome extensions when starting up my selenium chrome. But all extensions keep starting up each time I run the code. Is there a way of disabling the extensions.

public static void main(String[] args) throws IOException {
    System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability("chrome.binary", "C:\\Users\\ngzhongqin\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
    WebDriver driver = new ChromeDriver(capabilities);
    driver.get("http://www.cnn.com");
    WebElement searchBox = driver.findElement(By.name("q"));
}


推荐答案

找到了一个修复程序。 p>

Found a fix.

  capabilities.setCapability("chrome.switches", Arrays.asList("--disable-extensions"));

这篇关于如何禁用硒中的铬扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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