Install python (https://www.python.org/), download the latest Python version
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;
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 "/>
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 "/>
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 "/>
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.
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 "/>
-
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 () |
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)