Webdriver When you start Chrome, the default is to open a new user, not the default user. That is, the new user does not have us install the extension. in practice, however, we will need some extensions that the default user installs, for example, for some JS or CSS styles. It is important to use the default user when it is necessary to access the agent (since you will not be able to continue testing on new users after installing the extension).
A) extension of the default User:
In the locked Chrome taskbar, open the status:
b) webdriver the extension of the new user opened:
In the locked Chrome taskbar, open the status:
-----------------------------------------------------------------Body------------------------------------------------------ ------------------
Version Number Description: Selenium 2.0
Chrome: 34.0.1847.116 m
System: Windows 7 x86
The workaround:
Set Webdriver to start Chrome as the default user's configuration information (including bookmarks, extensions, etc.) chromeoptions options = new Chromeoptions (); Options.addarguments (" User-data-dir=c:/users/user_name/appdata/local/google/chrome/user data "); Webdriver Driver = new Chromedriver (options);
Note: In the example above, user_name is the username of your computer.
PS: The answer to the web search is a lot of the path User_data and added a default, but after I test is open chrome is still a new user.
Attached code:
Description
(1) Please ensure that the chromedriver path is correct;
(2) status.html in the js:src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" is unable to load success; JS loading success, The radio of the page is selected.
(3) Ensure that the proxy settings are normal.
Browser_chrome.java
package test;import org.testng.annotations.test;import org.openqa.selenium.By; Import Org.openqa.selenium.javascriptexecutor;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.webelement;import Org.openqa.selenium.chrome.chromedriver;import Org.openqa.selenium.chrome.chromeoptions;public class Browser_chrome {@Testpublic void Test () throws Interruptedexception{system.setproperty ("Webdriver.chrome.driver", "D:/setest/selenium/chromedriver.exe");// Set Webdriver to start Chrome as the default user's configuration information (including bookmarks, extensions, etc.) chromeoptions options = new Chromeoptions (); Options.addarguments (" User-data-dir=c:/users/test/appdata/local/google/chrome/user data "); Webdriver Driver = new Chromedriver (options);d river.get ("d:/setest/selenium/status-test.html"); Webelement Radio = driver.findelement (By.name ("Radio"));((Javascriptexecutor) driver). Executescript ("$ (' #radio '). Click (); "); System.out.println (radio.isselected ()); Thread.Sleep (+);//driver.close ();//driver.quit ();}}
Status-test.html
<! DOCTYPE html>
Execution (note the selection of extensions and radio--F12 developer tools – Direct access to JS scripts)
--------------------------------------------------------------------------------------------------------------- -----------------------------------------
Open new user chrome loading failed code and:
Browser_chrome.java(load failed code)
Package Test;import Org.testng.annotations.test;import Org.openqa.selenium.by;import Org.openqa.selenium.javascriptexecutor;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.webelement;import Org.openqa.selenium.chrome.chromedriver;public class Browser_Chrome {@ testpublic void Test () throws Interruptedexception{system.setproperty ("Webdriver.chrome.driver", "d:/setest/ Selenium/chromedriver.exe "); Webdriver Driver = new Chromedriver ();d river.get ("d:/setest/selenium/status-test.html"); Webelement Radio = driver.findelement (By.name ("Radio"));((Javascriptexecutor) driver). Executescript ("$ (' #radio '). Click (); "); System.out.println (radio.isselected ()); Thread.Sleep (+);//driver.close ();//driver.quit ();}}
Execute (load failed.) JS Open as empty):
References: Link 1
Set Webdriver to start Chrome as the default user's configuration information