Set Webdriver to start Chrome as the default user's configuration information

Source: Internet
Author: User
Tags testng


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 our extensions installed. However, in the actual application, we will need some extensions installed by default user, such as some JS or CSS style, need agent to access success, the use of the default user is particularly important (because you can not install the extension in the new user to continue testing).


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------------------------------------------------------ ------------------

Release Notes: Selenium 2.0

Chrome: 34.0.1847.116 m

System: Windows 7 x86


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 user name of your computer.

PS: The answer to the web search is a lot of the path User_data added a default, but after my test is open chrome is still a new user.



The reference code is attached:

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 successfully, 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>
Run (note the selection of extensions and radio--F12 developer tools – Direct access to JS scripts)










--------------------------------------------------------------------------------------------------------------- -----------------------------------------

Open new user chrome failed to load code and:

Browser_chrome.java(failed to load 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 ();}}

Run (load failed, JS Open is empty):











Reference: Link 1


Set Webdriver to start Chrome as the default user's configuration information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.