问题
anybody know why chrome arguments does't work?
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class testowa {
public static void main(String[] args) throws InterruptedException {
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability("chrome.args",
Arrays.asList("--disable-web-security", "--start-maximized"));
WebDriver driver = null;
try {
URL hub_url = new URL("http://192.168.56.101:4444/wd/hub");
driver = new RemoteWebDriver(hub_url, capability);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.get("file:///home/test/www/index.html");
}
}
I've tried also without "--" before switchers and giving only one argument... Chrome starts, but without activated flags.
I use newest chromedriver.
回答1:
I recently discovered that the Capabilities
class does not work properly with current Selenium and Chrome for some reason (as of Selenium 2.33.0, Chrome 30 and July 2013).
The answer I linked is also, I believe, the solution to your problem. Simply use ChromeOptions
, these have been working for me well:
ChromeOptions options = new ChromeOptions();
options.addArgument("--disable-web-security");
options.addArgument("--start-maximized");
// For use with RemoteWebDriver:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
回答2:
Those who are looking for .Net C# and Selenium, to load insecure script
ChromeOptions options = new ChromeOptions();
options.AddArguments("--allow-running-insecure-content");
IWebDriver driver = new ChromeDriver(options);
回答3:
Try something this, Change the path and slashing accoding to your specifications :-
WebDriver driver=null;
System.setProperty("webdriver.chrome.driver","./src//lib//chromedriver");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArgument("--start-maximized");
options.addArguments("--disable-web-security");
options.addArguments("--allow-running-insecure-content");
capabilities.setCapability("chrome.binary","./src//lib//chromedriver");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.get("https://www.google.com/");
Below is the link where all available chrome flags are listed :-
http://peter.sh/experiments/chromium-command-line-switches/
来源:https://stackoverflow.com/questions/17745550/chrome-arguments-doesnt-work