程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] selenium+python3 Usage Summary

編輯:Python

brief introduction

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

One 、 Process analysis :

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

Two 、 How the test framework is designed :

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 .

3、 ... and 、 install python-selenium

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

Four 、 Install browser driver

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

5、 ... and 、 Configure environment variables ( Browser driven )

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

6、 ... and 、 A simple example

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved