1. Installing Selenium
On the command line, enter:
Show installation success:
2. Test examples
Open the Baidu page and enter the search in the input box (default is Firework)
1 #1. Selenium default to Firefox. Validation2 fromSeleniumImportWebdriver3 4Driver =Webdriver. Firefox ()5 #The control of Webdriver Firefox assigned to driver; Get browser object to launch browser, open URL, action page6 7Driver.get ("http://www.baidu.com")8 #after getting the browser object, you can send the URL to the browser via the Get () method9 TenDRIVER.FIND_ELEMENT_BY_ID ('kw'). Send_keys ('Hello') One #here, navigate to the search box by id = kw and enter ' hello ' into the input box via the keyboard method Send_keys A -DRIVER.FIND_ELEMENT_BY_ID ('kw'). Submit () -Driver.close ()
Note: Selenium 2.53 support Firefox47 version and below, remember to remove the "browser update", or error
Do not upgrade firefox!! casually
3.
Installing browser Drivers
(i)
IE
Browser
A) first downloaded in http://selenium-release.storage.googleapis.com/index.html: iedriverserver
b) after decompression, place in the path of the environment variable path:
C:\Users\lesleysbw\AppData\Local\Programs\Python\Python35\
And:
C:\Program Files (x86) \internet Explorer
c) Set up IE browser:
Click on the "Settings"--inter option--Secure, set all zone levels to:, and remove "Enable protected mode":
d) Run the code:
1 from Import Webdriver 2 3 Driver = webdriver. Ie ()4 driver.get ("http://www.baidu.com")5 6 driver.find_element_by_id ('kw'). Send_keys ('Hello ')
(ii)
Chrome
Browser
a) Download chromedriverserver:http://npm.taobao.org/mirrors/chromedriver/2.9/
After decompression, place the ChromeDriverServer.exe in the path of the environment variable path:
C:\Users\lesleysbw\AppData\Local\Programs\Python\Python35\
and the path to Chrome:
C:\Program Files (x86) \google\chrome\application
b) Set path: Add ChromeDriverServer.exe path:
C:\Program Files (x86) \google\chrome\application
c) Run the code:
1 from Import Webdriver 2 Driver = webdriver. Chrome ()3 driver.get ("http://www.baidu.com")4 5 driver.find_element_by_id ('kw'). Send_keys ('Hello ')
Two. Python Webdriver Environment Setup