Selenium is an open-source testing tool developed by ThoughtWorks and is used primarily for web-side automated testing.
Python installs selenium and installs directly using the PIP install Selenium (python) command, which is installed by default and is up-to-date, That is selenium 3.x version, the previous selenium2.x version of the time, is the driver with Firefox, directly open Firefox browser, now 3.x version, open Firefox also need to specify the driver, share a bit below, the driver download of each browser, and how to open the browser, do some simple operation , how to write the code. 1. Firefox (firefox) The Firefox driver is: https://github.com/mozilla/geckodriver/releases/
According to your own operating system to download the corresponding driver, if used, you need to add the path of the drive and the path of the Firefox browser to the environment variables can be 2, Chrome (Google)Chrome Browser driver:/http Chromedriver.storage.googleapis.com/index.html
Google's drivers have many versions, according to their own browser version to choose the corresponding version of the driver, Windows version of the only Win32, 64-bit operating system is also applicable, also need to add the Google Browser directory and drive path to the environment variables, browser version of the corresponding driver version see below:
Chromedriver version |
supported versions of Chrome |
v2.29 |
v56-58 |
v2.28 |
v55-57 |
v2.27 |
v54-56 |
v2.26 |
V53-55 |
v2.25 |
V53-55 |
v2.24 |
v52-54 |
v2.23 |
v51-53 |
v2.22 |
v49-52 |
v2.21 |
V46-50 |
v2.20 |
v43-48 |
v2.19 |
v43-47 |
v2.18 |
v43-46 |
v2.17 |
v42-43 |
v2.13 |
V42-45 |
v2.15 |
v40-43 |
v2.14 |
V39-42 |
v2.13 |
v38-41 |
v2.12 |
V36-40 |
v2.11 |
V36-40 |
v2.10 |
V33-36 |
v2.9 |
V31-34 |
v2.8 |
V30-33 |
v2.7 |
V30-33 |
v2.6 |
V29-32 |
v2.5 |
V29-32 |
v2.4 |
V29-32 |
3. IE IE Browser driver: http://selenium-release.storage.googleapis.com/index.html
Download the corresponding version of the driver according to your selenium version, Python, Download inside the Iedriverserverxxx.zip can, this is to distinguish between 32 and 64 bit system, according to own system download can, need to note is, if you want to open IE browser, need in browser Internet options in the Security page has 4 security options, the Internet , local internet, Trusted sites, Restricted sites, all 4 of them have a protected mode enabled, they need to be checked, and the drive path is added to the environment variable.
Here is the simple code, how to open in various browsers with selenium open Baidu, of course, to open which browser, you must write all I have done before you can.
123456789101112 |
from selenium import webdriver #导入webdriver import timeURL = ' http://www.nnzhp.cn ' #要打开的网站 b = webdriver. Firefox()#打开火狐浏览器 # b = Webdriver. Chrome () #打开chrome浏览器# b = Webdriver. Ie () #打开ieb. Get(URL) #打开上面的url time. Sleep(3) b. Quit()#关闭浏览器 |
Seleniumwebdriver Browser Driver Information summary