Selenium installation and simple and practical

Source: Internet
Author: User
Tags blank page

Introduction

Selenium is a tool for Web application testing.

The selenium test runs directly in the browser, just as the real user is doing. Supported browsers include IE (7, 8, 9, ten, one), Firefox,safari,chrome,opera, etc.

The main features of this tool include: test and browser compatibility--test your application to see if it works well on different browsers and operating systems. Test system functions--Create regression test to verify software functionality and user requirements.

The use of the crawler is to simulate the normal user access to the Web page and obtain data. We can use it to simulate the user clicking to visit the website, bypassing some complex authentication scenarios

By selenium + Driver browser This combination can directly render parsing JS, bypassing most of the parameter construction and anti-crawling

Precautions:

The new version of Selenium has not supported Phantomis, and the original author has given up on maintaining the project.

Install Chromedriver (browser-driven) installation

Using selenium to drive a Chrome browser requires downloading Chromedriver, and the chromedriver version needs to correspond to the chrome version, and the wrong version will run an error.

Chromedriver:http://chromedriver.storage.googleapis.com/index.html

Chromedriver and Chrome version mapping table:

Chromedriver version supported versions of Chrome
v2.37 v64-66
v2.36 V63-65
v2.35 V62-64
v2.34 v61-63
v2.33 v60-62
v2.32 v59-61
v2.31 V58-60
v2.30 V58-60
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
Mac/linux

After the download is complete, the file is moved to the /usr/local/bin directory, and it is available for normal use.

Windows

After the download is complete, move the file to a folder that has the environment variable configured, such as your Python installation folder.

Selenium installation

SeleniumThe installation is very simple, direct PIP can be done.

Pip Install Selenium

Simple to use

Now run a blank page of the browser window

 fromSeleniumImportWebdriver fromSelenium.webdriver.chrome.optionsImportOptions#instantiate a startup Parameter objectChrome_options = Options()#set browser window sizeChrome_options.add_argument('--window-size=1366,768')#Launch BrowserBrowser = Webdriver.Chrome(chrome_options=chrome_options)

Click to run, it will automatically pop up a blank browser window.

Next, we try to visit Baidu's first page

 fromSeleniumImportWebdriver fromSelenium.webdriver.chrome.optionsImportOptions#instantiate a startup Parameter objectChrome_options =Options ()#set browser window sizeChrome_options.add_argument ('--window-size=1366,768')#Launch BrowserBrowser = Webdriver. Chrome (chrome_options=chrome_options)#Request Baidu HomepageBrowser.get ('http://www.baidu.com')

This program click Run, pop-up browser will automatically go to the homepage of Baidu

More detailed content, which will be covered in the following

Selenium installation and simple and practical

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.