Operation of the "Selenium topic" Selenium chromedriver

Source: Internet
Author: User
Tags selenium chromedriver

Selenium Operation Chrome Browser requires Chromedriver driver to assist.
First, what is Chromedriver?
Chromedriver is a chromium team development and maintenance, it is a separate service to implement the Webdriver cable protocol. Chromedriver controls the browser via Chrome's auto-proxy framework, and Chromedriver is only compatible with Chrome browser versions above 12.0.712.0.

Second, start the Chrome browser
So if you want to selenium a successful operation, the Chrome browser needs to go through the following steps:
1. Download Chromedriver driver package (: http://chromedriver.storage.googleapis.com/index.html?path=2.7/

Note Read Note.txt Download the same version of the driver package that you use for your browser.
2. Specify the location of the chromedriver, which can be specified in two ways:
1) by configuring the ChromeDriver.exe location to the PATH environment variable implementation.
2) implemented by Webdriver.chrome.driver. System Properties. The implementation code is as follows:
System.setproperty ("Webdriver.chrome.driver", "C:\Documents and Settings\Administrator\Local Settings\Application Data\google\chrome\application\chromedriver.exe ");
3. The last thing to do is to create a new instance of Chromedriver.
Webdriver Driver = new Chromedriver ();
Driver.get ("http://www.baidu.com/");
We are now able to execute our automation code through the Chrome browser.
The full instance code is as follows:

public static void Main (string[] args) {

TODO auto-generated Method Stub

Set the path to access Chromedriver

System.setproperty ("Webdriver.chrome.driver", "C:\Documents and Settings\administrator\localsettings\application Data\google\chrome\application\chromedriver.exe ");

Webdriver Driver = new Chromedriver ();

Driver.get ("http://www.baidu.com/");

}
Btw
Chrome browser in each system default location:
OS expected location of Chrome
Linux/usr/bin/google-chrome1
Mac/applications/google Chrome.app/Contents/MacOS/Google Chrome
Windows XP%homepath%local settingsapplication DataGoogleChromeApplicationchrome.exe
Windows Vista C:users\%username%appdatalocalgooglechromeapplicationchrome.exe

Third, Chromedriverservice

Executing the above code you will find that Chromedriver is only when the creation is started, call quit when the browser is closed, Chromedriver is a lightweight service if the boot is shut down frequently in a larger test suite, Will add a noticeable delay that causes the browser process not to be closed, in order to avoid this situation we can control the life and death of the chromedriver process through Chromedriverservice, The effect of closing is achieved to avoid the occurrence of process usage (Running the server in a child process).
The specific implementation is as follows:
Chromedriverservice service = new Chromedriverservice.builder (). usingchromedriverexecutable (The new File ("E:\Selenium Webdriver\chromedriver_win_23.0.1240.0\chromedriver.exe ")). Usinganyfreeport (). build ();
Service.start ();
Driver = new Chromedriver ();
Driver.get ("http://www.baidu.com");
Driver.quit ();
Close the Chromedriver interface
Service.stop ();

"Turn from" http://www.spasvo.com/ceshi/open/kygncsgj/Selenium/20131213102816.html

Operation of the "Selenium topic" Selenium chromedriver

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.