Python install selenium, configure Firefox environment

Source: Internet
Author: User

When you want to use Python to write an automated script for Web page access, you encounter some problems,

 File  c:\python34\lib\site-packages\ selenium-3.0.0b2-py3.4.egg\selenium\webdriver\common\service.py   ", Line, in   startstdout  =self.log_file, Stderr=self.log_file) file   " c:\python34\lib\subprocess.py  " , line 859, in  __init__  restore_ Signals, start_new_session) File   " c:\ python34\lib\subprocess.py  , line 1112,  In   _execute_childstartupinfo) Filenotfounderror: [Winerror  2] The system cannot find the file specified. 

This is because the environment is not configured well, the configuration environment is not difficult, is cumbersome.

Firefox can be downloaded directly from the Internet,

Geckodriver Download Link: https://github.com/mozilla/geckodriver/releases

After downloading, install Firefox browser, install as the default address C:\Program Files (x86) \mozilla Firefox; When the installation is complete, open Firefox browser and configure the Selenium IDE plugin.

First step: Open Firefox browser, find the right-most menu, select Add-ons,:

Second step: Open the Attachment component, select "Get Attachment Component", search the Selenium IDE in the search box

The third step: Find the Selenium IDE added to Firefox, to install;

Fourth step: After the installation, restart the browser, the tool list will appear under the Selenium IDE;

Selenium IDE Plug-in is installed, click Enable to record the script.

Fifth step: Will download good geckodriver decompression, will geckodriver.exe placed in the Firefox browser installed directory, C:\Program Files (x86) \mozilla Firefox;

Sixth step: Configure the environment, open the computer, select System Properties, select Advanced System settings, click Environment variables, the path of PIP in Python (C:\Users\Administrator\AppData\Local\Programs\Python\ python35-32\scripts;) added to the environment variable;

Seventh Step: Win+r Open terminal, enter PIP install, no error, and explain the environment configuration is successful, enter PIP install selenium in the terminal; You can install the Selenium module in Python;

Eighth step: Add the Firefox path to the environment variable (C:\Program Files (x86) \mozilla Firefox;); in the terminal input Firefox.exe, the browser is automatically enabled, then the environment is configured successfully!!!

At this point, compile the code again, you can succeed ...

#Coding:utf-8 fromSeleniumImportWebdriverImportTimebrower=Webdriver. Firefox () Brower.get ("http://www.baidu.com") brower.find_element_by_id ('kw'). Send_keys ('Selenium') brower.find_element_by_id ('su'). Click () time.sleep (3) Brower.close ()

Python install selenium, configure Firefox environment

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.