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

前端 未结 2 398
傲寒
傲寒 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;
        }
    

提交回复
热议问题