Selenium Is a project covering a range of tools and Libraries , These tools and libraries support and support Web Browser automation .
It provides extensions to simulate user browser interaction 、 Distributor for extended browser assignment , And for the implementation of W3C WebDriver Standardized infrastructure , Allows you to provide all major Web Browsers write interchangeable code
Selenium The core is WebDriver, This is an interface for writing instruction sets , Can run interchangeably in many browsers . After installing everything , Just a few lines of code to enter the browser . You can write your first Selenium Find more comprehensive examples in the script
selenium Official website
Chinese use documents
WebDriver Talk to the browser through the driver . There are the following ways to communicate :
1、WebDriver Pass commands to the browser through the driver , And receive the returned information through the same route . The driver and browser run on the same system
2、 Communication with the browser can also be through Selenium Server or RemoteWebDriver Remote communication .RemoteWebDriver Run on the same system as the driver and browser .
3、 Telecommunication can also use Selenium Server or Selenium Grid Conduct , These two, in turn, communicate with the driver on the host system
Communicate with the browser through any of the above methods .WebDriver Know nothing about testing : It doesn't know how to compare things , Assert or fail .
This is where the various frameworks work . You need at least one testing framework that matches the language binding , For example .NET Of NUnit、 be used for Java Of JUnit、 be used for Ruby Of RSpec etc. .
The test framework is responsible for running and executing your WebDriver And the relevant steps in the test . therefore , You can think of it as something like the following figure .
Natural language framework / Tools ( for example Cucumber or Robotium) It may exist as part of the test framework box in the above figure , Or they might wrap the test framework entirely in their own implementation .
1、 The premise is already installed python( Refer to the following article to install ):
【python Basics 】windows Install and use python
2、 Then execute the following command :
pip install selenium
3、 Installation error report solution :
error: can't find Rust compiler
This package requires Rust >=1.41.0.
# Solution upgrade pip:
python -m pip install -U --force-reinstall pip
Drivers are browser specific , Google's Chrome/Chromium Of ChromeDriver,Mozilla Of Firefox GeckoDriver etc. .
1、 Google browser driver download
chromedriver download
After downloading, put it in the specified path and unzip it , My decompression path is :F:\seleniumdriver\chromedriver.exe
2、 Firefox browser driver download
firefox (Firefox) Of GeckoDriver Driver download
My computer –> attribute –> System settings –> senior –> environment variable –> System variables –>Path
stay path Add... To the path driver The storage path of is :
;F:\seleniumdriver
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")