如何在 selenium 中禁用 Chrome 扩展 [英] how to disable chrome extension in selenium

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

问题描述

我试图在启动 selenium chrome 时禁用所有 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"));
}

 

推荐答案

已找到修复.

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

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

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