我想禁用"禁用开发者模式扩展"按照本文keep "Disable developer mode" closed while adding extension
中提到的那样保留扩展名没有答案,我试图做同样的事情。 Selenium有没有像这样的chrome选项?
答案 0 :(得分:0)
以下是您的问题的答案:
在使用Selenium 3.4.0,chromedriver v2.30,Google Chrome 59.0通过Java绑定时,您可以使用ChromeOption类来禁用"禁用开发者模式扩展程序"弹出如下:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class Q44959944_dev_extn {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.navigate().to("https://google.com");
}
}
如果这回答你的问题,请告诉我。
答案 1 :(得分:0)
DebanjanB提供的解决方案不适用于最新版本的Chrome和Chrome驱动程序。
要使其正常工作,您需要指定排除开关,并在prefs标志中使用autoAutomationExtension。
System.setProperty("webdriver.chrome.driver", Constant.BROWSER_CHROME_PATH);
Map prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.geolocation", 1); // 1:allow 2:block
prefs.put("useAutomationExtension", false);
prefs.put("excludeSwitches", Collections.singletonList("enable-automation"));
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("-incognito");
chromeOptions.addArguments("--disable-gpu"); // applicable to windows os only
chromeOptions.setExperimentalOption("prefs", prefs);
chromeOptions.addArguments("--no-sandbox");
wDriver = new ChromeDriver(chromeOptions);
((LocationContext)wDriver).setLocation(new Location(37.774929, -122.419416, 0));
wDrivers.put("chrome", wDriver);
log.info("New Chrome Browser Instance Created.");