How do I pass arguments to google chrome when running selenium?

前端 未结 2 399
傲寒
傲寒 2021-01-20 14:07

I want to be able to pass arguments to google chrome when running selenium. How can I do that? When I run selenium I use the Java command Java -jar selenium.jar

How

相关标签:
2条回答
  • 2021-01-20 14:21

    You can send them in your method for launching the driver. e.g.

    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;
        }
    
    0 讨论(0)
  • 2021-01-20 14:36

    In nightwatch you should include chromeOptions with no-sandbox args into desiredCapabilities as below :-

    "desiredCapabilities" : {
      "browserName" : "chrome",
      "javascriptEnabled" : true,
      "acceptSslCerts" : true,
      "chromeOptions" : {
        "args" : ["--no-sandbox"]
      }
    }
    
    0 讨论(0)
提交回复
热议问题