【问题标题】:How do I pass arguments to google chrome when running selenium?运行 selenium 时如何将参数传递给谷歌浏览器?
【发布时间】:2016-08-19 14:08:44
【问题描述】:

我希望能够在运行 selenium 时将参数传递给 google chrome。我怎样才能做到这一点?当我运行 selenium 时,我使用 Java 命令 Java -jar selenium.jar

如何将 no-sandbox、ignore-gpu-blacklist、enable-webgl 等参数传递给 google chrome 可执行文件。谢谢

我正在使用守夜人

【问题讨论】:

标签: google-chrome selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

您可以在启动驱动程序的方法中发送它们。例如

public static WebDriver chromeBrowser() throws Throwable {
        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver-location\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--no-sandbox");
        WebDriver browser = new ChromeDriver(options);
        browser.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        return browser;
    }

【讨论】:

  • 人在使用 nightwatch.js,你提到了 Java 代码。
  • @Grasshopper 但你明白他的意思
【解决方案2】:

nightwatch 中,您应该将chromeOptionsno-sandbox args 包含在desiredCapabilities 中,如下所示:-

"desiredCapabilities" : {
  "browserName" : "chrome",
  "javascriptEnabled" : true,
  "acceptSslCerts" : true,
  "chromeOptions" : {
    "args" : ["--no-sandbox"]
  }
}

【讨论】:

  • 我在使用 javascript 和 WebDriver 是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-17
  • 1970-01-01
  • 1970-01-01
  • 2018-02-06
  • 1970-01-01
  • 2017-04-02
  • 1970-01-01
相关资源
最近更新 更多