WebDriver | Selenium
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");
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2021-03-16 Microsoft AZ-900 Exam Actual Questions
2021-03-16 What is a private cloud?
2021-03-16 Commodity Hardware
2021-03-16 Azure Fundamental 测试题1:云概念
2021-03-16 Willpower Doesn’t Work by Benjamin P. Hardy (BOOK NOTES)
2020-03-16 JQuery: Convert GET URL to POST
2020-03-16 This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request.