java 运行 selenium 脚本时无法从弹出框中加载扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43797119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to load extension from popup box while running selenium scripts
提问by kaushik3993
I get the following popup box when I try to run my selenium script in java:
当我尝试在 Java 中运行我的 selenium 脚本时,我得到以下弹出框:
Failed to load extension from:
C:\Users\xyz\AppData\Local\Temp\scoped_dir20432_5430\internal. Loading of unpacked extensions is disabled by the administrator.
I have tried chromeoption
arguments
I have found in other pages. But none seems to work.
我试过chromeoption
arguments
我在其他页面找到的。但似乎没有一个工作。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
public class testClass {
public static String driverPath = "D:/Selenium/Chrome Driver latest/chromedriver.exe";
public static WebDriver driver;
public static void main(String args[]) {
System.setProperty("webdriver.chrome.driver", driverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("--js-flags=--expose-gc");
options.addArguments("--enable-precise-memory-info");
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-default-apps");
options.addArguments("--enable-automation");
options.addArguments("test-type=browser");
options.addArguments("disable-infobars");
options.addArguments("disable-extensions");
driver = new ChromeDriver(options);
driver.navigate().to("http://google.com");
driver.quit();
}
}
I am forced to handle that popup manually. How do I get rid of it ?
我被迫手动处理该弹出窗口。我该如何摆脱它?
回答by Markus Dietler
I had the same problem and I finally found a working answer in another thread. Loading of unpacked extensions is disabled by the administrator
我遇到了同样的问题,我终于在另一个线程中找到了有效的答案。 管理员禁止加载解压扩展
The following line did the trickt for me
以下行对我有用
options.setExperimentalOption("useAutomationExtension", false);
There are some trade-offs mentioned in the link, like window resizing operations with the Chrome automation extension aren't possible anymore. Anyway, starting with the start-maximized argument still worked fine in my code.
链接中提到了一些权衡,例如不再可能使用 Chrome 自动化扩展程序调整窗口大小。无论如何,从 start-maximized 参数开始在我的代码中仍然可以正常工作。
options.addArguments("start-maximized");