以下方法无法正常工作。 由于使用了GRID,因此功能设置为 null 。
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
DesiredCapabilities capability=null;
方法1:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir=C:/Users /username/AppData/Local/Google/Chrome/User Data/Default"));
driver = new ChromeDriver(capabilities);
方法2:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
String chromeProfile = "C:/Users/username/AppData/Local/Google/Chrome/Application /chrome.exe";
ArrayList<String> switches = new ArrayList<String>();
switches.add("C:/Users/username/AppData/Local/Google/Chrome/User Data/Default" + chromeProfile);
capabilities.setCapability("chrome.switches", switches);
driver = new ChromeDriver(capabilities);
答案 0 :(得分:2)
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data");
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
如果您遇到这样的错误:
org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:正常退出
然后尝试创建新的Chrome个人资料并执行测试。
'User Data'
e.g., New User
C:/Users/user_name/AppData/Local/Google/Chrome/New User
答案 1 :(得分:0)
1在启动节点时设置chromedriver属性。我的方法:
java -jar selenium-server-standalone-2.31.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=lib\chromedriver.exe
2在代码中我的方法:
capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
3加载HTTP基本身份验证页面:
String username = "Pavel";
String password = "Omgtoosecrettotellyou";
driver.get("http://" + username + ":" + password + "@" +"your-site.com");