Selenium (1): selenium installation in Python, seleniumpython

Source: Internet
Author: User

Selenium (1): selenium installation in Python, seleniumpython
About selenium

Selenium is also a tool for Web application testing. The Selenium test runs directly in the browser, just as the real user is operating. Supported browsers include IE, Mozilla Firefox, and Mozilla Suite. The main features of this tool include testing the compatibility with browsers-testing your applications to see if they can work well on different browsers and operating systems. Test System functions-create a decline test to test the software functions and user requirements. Supports automatic recording and automatic generation. . Net, Java, Perl, and other testing scripts in different languages. Selenium is an acceptance test tool specially written by ThoughtWorks for Web applications.

Install the selenium package

Run the pip install selenium command. Wait until the installation is complete!

Download the browser driver

After selenium is upgraded to 3.0, different browser drivers are standardized. If you want to use selenium to drive different browsers, you must separately download and set different browser drivers. Of course, the corresponding browser must be available. The browser drivers of different versions correspond to different browser versions. You must select a match when downloading. Personal experience: Chrome and Firefox are both good. Firefox is good for beginners. There are related driver updates on github, which will save some trouble.
Various browser drivers:
Firefox DRIVER: geckodriver
Chrome DRIVER: chromedriver
Internet Explorer DRIVER: IEDriverServer
Edge browser DRIVER: MicrosoftWebDriver
Operabrowser DRIVER: operadriver
PhantomJS browser DRIVER: phantomjs
Note: Some browser driver addresses require scientific Internet access.

Set browser driver

Setting the browser address is very simple. You can manually create a directory to store the browser driver, such as C: \ driver, and drop the downloaded browser driver files (such as chromedriver and geckodriver) to this directory.
My computer-> properties-> system settings-> advanced-> environment variables-> system variables-> Path, add the "C: \ driver" directory to the Path value, verify that different browser drivers are working properly:

From selenium import webdriver

Driver = webdriver. Firefox () # Firefox
Driver = webdriver. Chrome () # Chrome browser
Driver = webdriver. Ie () # Internet Explorer
Driver = webdriver. Edge () # Edge Browser
Driver = webdriver. Opera () # operabrowser
Driver = webdriver. PhantomJS () # PhantomJS
Test selenium
Import time
From selenium import webdriver
 
Driver = webdriver. Firefox () # Open Firefox
Driver. get ('HTTP: // www.baidu.com ') # Open the Baidu Interface
Driver. find_element_by_id ('kw '). send_keys ('www. 5bug. wang') # enter the content you want to search in the search box
Time. sleep (2) # time required for loading the browser
Driver. find_element_by_id ('su '). click () # search complete

When your browser is automatically opened and the keyword www.5bug. wang is searched, it indicates that the python and selenium environments are set up.

Note: The content of this article is based on the articles shared by students in the blog garden!

Related Article

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.