Two. Python Webdriver Environment Setup

Source: Internet
Author: User

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

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.