Selenium first example with Python (Windows system)

Source: Internet
Author: User

  1. Install python (https://www.python.org/), download the latest Python version

  2. Configure environment variables. (Example), I installed Python under/installation folder with Python 3.5.2. The path set is as follows:

    d:\installation\python3.5.2;d:\installation\python3.5.2\scripts;

  3. Install Pip (you could search related steps from the Internet to install)

    (Locate To/scripts folder, to perform easy_install pip command

    650) this.width=650; "Title=" easy. JPG "alt=" wkiol1jquikcvhljaac-y-edlyq518.jpg-wh_50 "src=" https://s4.51cto.com/wyfs02/M01/8E/F9/ Wkiol1jquikcvhljaac-y-edlyq518.jpg-wh_500x0-wm_3-wmp_4-s_3502238631.jpg "/>

  4. If installation success, type pip command to check

    650) this.width=650; "Title=" Pip. JPG "alt=" wkiom1jquriho1fwaaihhhvbgys130.jpg-wh_50 "src=" https://s2.51cto.com/wyfs02/M00/8E/FC/ Wkiom1jquriho1fwaaihhhvbgys130.jpg-wh_500x0-wm_3-wmp_4-s_292698118.jpg "/>

  5. Install Selenium. To perform command pip install-u Selenium

    650) this.width=650; "title=" Selenium. JPG "alt=" wkiol1jquzhdr7oqaabuhl5wdy4077.jpg-wh_50 "src=" https://s5.51cto.com/wyfs02/M01/8E/FA/ Wkiol1jquzhdr7oqaabuhl5wdy4077.jpg-wh_500x0-wm_3-wmp_4-s_3756686250.jpg "/>

  6. Till now, Python and Selenium had been installed successfully, then you were able to the create Python code to drive browser. Here we using the Edge browser to check.

  7. Before need to download Edge driver (https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/) and put it on Python installation Foloder (D:\installation\Python3.5.2)

    650) this.width=650; "title=" driver. JPG "alt=" wkiom1jqvkmzj6z5aadzoimrmb0422.jpg-wh_50 "src=" https://s3.51cto.com/wyfs02/M02/8E/FC/ Wkiom1jqvkmzj6z5aadzoimrmb0422.jpg-wh_500x0-wm_3-wmp_4-s_3252056851.jpg "/>

  8. From selenium import Webdriver


    Driver = Webdriver. Edge ()

    Driver.get ("https://www.baidu.com")

    Print ("width:600,height:800")

    Driver.set_window_size (600,800)

    Driver.quit ()


  1. Look at the source code to see how the above code works

    first First in lib site-packages Selenium

D:\ Installation\python3.5.2\lib\site-packages\selenium,selenium Webdriver

650) this.width=650; "title=" 1.png "alt=" wkiom1jqvcfdq_wbaadih_du3_i462.png-wh_50 "src=" https://s1.51cto.com/ Wyfs02/m00/8e/fc/wkiom1jqvcfdq_wbaadih_du3_i462.png-wh_500x0-wm_3-wmp_4-s_2878955867.png "/>

this is __init__.py the Code

650) this.width=650; "title=" 2.png "alt=" wkiol1jqvf6wd-9daabpzmptu0i809.png-wh_50 "src=" https://s1.51cto.com/ Wyfs02/m00/8e/fa/wkiol1jqvf6wd-9daabpzmptu0i809.png-wh_500x0-wm_3-wmp_4-s_1341738541.png "/>


Import from current directory Webdriver class, and then give it an alias, such as Edge (the corresponding code call is Webdriver. Edge (), Otherwise it should be written Webdriver. Webdriver ())

Open Webdriver class of code,

650) this.width=650; "title=" 3.png "alt=" wkiol1jqvi3hdle9aaclbdxuz90923.png-wh_50 "src=" https://s1.51cto.com/ Wyfs02/m01/8e/fa/wkiol1jqvi3hdle9aaclbdxuz90923.png-wh_500x0-wm_3-wmp_4-s_2437535230.png "/>


There are two methods, one is the initial__init__, one isquit, callingEdge ()then execute__init__method, and finally closeEdgecalled whenquit ()Method


This article is from the "Waytogo" blog, make sure to keep this source http://waytogo.blog.51cto.com/12732809/1908750

Selenium first example with Python (Windows system)

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.