WebDriver | Selenium
安裝分兩步,先安裝nuget package,然後再安裝chrome driver
https://github.com/seleniumhq/selenium 源碼
https://www.nuget.org/packages/Selenium.WebDriver#versions-body-tab nuget
WebDriver drives a browser natively, as a user would, either locally or on a remote machine using the Selenium server, marks a leap forward in terms of browser automation.
Selenium WebDriver refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just WebDriver.
Selenium WebDriver is a W3C Recommendation
-
WebDriver is designed as a simple and more concise programming interface.
-
WebDriver is a compact object-oriented API.
-
It drives the browser effectively.
Getting started
If you are new to Selenium, we have a few resources that can help you get up to speed right away.
Web elements
Identifying and working with element objects in the DOM.
Actions API
A low-level interface for providing virtualized device input actions to the web browser.
Support features
Support classes provide optional higher level features.
Troubleshooting Assistance
How to get manage WebDriver problems.
Install a Selenium library | Selenium
First you need to install the Selenium bindings for your automation project. The installation process for libraries depends on the language you choose to use. Make sure you check the Selenium downloads page to make sure you are using the latest version
A list of all supported frameworks for each version of Selenium is available on Nuget
There are a few options for installing Selenium.
Packet Manager
Install browser drivers | Selenium
Install browser drivers
Through WebDriver, Selenium supports all major browsers on the market such as Chrome/Chromium, Firefox, Internet Explorer, Edge, and Safari. Where possible, WebDriver drives the browser using the browser’s built-in support for automation.
Since all the driver implementations except for Internet Explorer are provided by the browser vendors themselves, they are not included in the standard Selenium distribution. This section explains the basic requirements for getting started with the different browsers.
Read about more advanced options for starting a driver in our driver configuration documentation.
1. Selenium Manager (Beta)
Selenium Manager helps you to get a working environment to run Selenium out of the box. Beta 1 of Selenium Manager will configure the drivers for Chrome, Firefox, and Edge if they are not found on the PATH
. No extra configuration is needed. Future releases of Selenium Manager will eventually even download browsers if necessary.
Read more at the blog announcement for Selenium Manager .
2. Driver Management Software
Most machines automatically update the browser, but the driver does not. To make sure you get the correct driver for your browser, there are many third party libraries to assist you.
Important: This package does not currently work for IEDriverServer v4+
- Import WebDriver Manager Package 這個對應的github源碼是,GitHub - rosolko/WebDriverManager.Net: Automatic Selenium Webdriver binaries management for .Net
nuget安裝包是https://www.nuget.org/packages/WebDriverManager/
Install-Package WebDriverManager
- Use the
SetUpDriver()
which requires a config class:
3. The PATH
Environment Variable
This option first requires manually downloading the driver (See Quick Reference Section for links).
This is a flexible option to change location of drivers without having to update your code, and will work on multiple machines without requiring that each machine put the drivers in the same place.
You can either place the drivers in a directory that is already listed in PATH
, or you can place them in a directory and add it to PATH
.
To see what directories are already on PATH
, open a Command Prompt and execute:
If the location to your driver is not already in a directory listed, you can add a new directory to PATH:
You can test if it has been added correctly by starting the driver:
4. Hard Coded Location
Similar to Option 3 above, you need to manually download the driver (See Quick Reference Section for links). Specifying the location in the code itself has the advantage of not needing to figure out Environment Variables on your system, but has the drawback of making the code much less flexible.
var driver = new ChromeDriver(@"C:\WebDriver\bin");