Selenium2+python automation 2-pip downgrade selenium3.0

 

An exception occurs when starting Firefox after the selenium version is installed: 'geckodriver' executable needs to be in PATH

Selenium has been silently upgraded to 3.0. However, the online tutorials are all based on selenium 2. Recently, many friends have stepped on the pit and decided that it is necessary to publish this article to help the new friends solve environmental problems.

Selenium+python environment collocation:

Selenium2+firefox46 or lower (no driver package required, firefox likes to upgrade secretly, you know)

Selenium3+firefix47 and above (the driver must be downloaded: geckodriver.exe, and added to the environment variable)

1. An exception is encountered

    1. After installing selenium, cmd enters the python environment

    2. Import webdriver from selenium

    3. Launch Firefox browser

>>python

>>from selenium import webdriver

>>webdriver.Firefox()

Then I get the following exception: 'geckodriver' executable needs to be in PATH

2. Solutions

    1. 'geckodriver' executable needs to be in PATH, which means that the driver file of geckodriver.exe needs to be added to the environment variable,

Selenium2 supports firefox by default and does not need a driver package. However, selenium3 needs the support of a driver package, so there are the above problems

   2. Solution 1: Continue to use selenium3, download the driver package, and then add it to the environment variable (this method is not recommended, because after solving this problem, there will be other problems later)

   3. Solution 2: downgrade selenium3 to selenium2 (will be introduced next)

 

3. Check the pip environment

    1. Open cmd, enter pip, and check whether the pip environment is normal

>>pip

    2. If the prompt: Did not provide a command appears when entering pip, it means that there is a problem with the pip environment. The temporary solution is to add the suffix pip.exe when entering pip. For the specific reasons, see the next solution.

Fourth, pip to view the selenium version number

    1. Open cmd and enter pip show selenium

>>pip show selenium

   2. Look at the version number display in the red area: 2.53.0, which shows the version number currently in use

(If you are showing the beginning of 3.0 here, you need the next steps)

Five, pip downgrade selenium

    1. In order to avoid conflicts with the previously installed selenium version, first find the selenium3.0 directory: python\Lib\site-packages directory

Just delete all the files that start with selenium. All third-party packages of python are under this directory.

     2. Open cmd and enter pip install selenium==2.53.6 (note that there are two ==, do not leave spaces in between, the version 2.53.6 is recommended here)

>>pip install selenium==2.53.6

 

Six, upgrade pip version

    1. If the words in the red area below appear during the use of pip, it means that the version of pip is too low, and it is recommended to upgrade

    2. How to upgrade pip? Look at the last sentence: python -m pip install --upgrade pip

 

   3. Just tap the corresponding prompts above.

 

An exception occurs when starting Firefox after the selenium version is installed: 'geckodriver' executable needs to be in PATH

Selenium has been silently upgraded to 3.0. However, the online tutorials are all based on selenium 2. Recently, many friends have stepped on the pit and decided that it is necessary to publish this article to help the new friends solve environmental problems.

Selenium+python environment collocation:

Selenium2+firefox46 or lower (no driver package required, firefox likes to upgrade secretly, you know)

Selenium3+firefix47 and above (the driver must be downloaded: geckodriver.exe, and added to the environment variable)

1. An exception is encountered

    1. After installing selenium, cmd enters the python environment

    2. Import webdriver from selenium

    3. Launch Firefox browser

>>python

>>from selenium import webdriver

>>webdriver.Firefox()

Then I get the following exception: 'geckodriver' executable needs to be in PATH

2. Solutions

    1. 'geckodriver' executable needs to be in PATH, which means that the driver file of geckodriver.exe needs to be added to the environment variable,

Selenium2 supports firefox by default and does not need a driver package. However, selenium3 needs the support of a driver package, so there are the above problems

   2. Solution 1: Continue to use selenium3, download the driver package, and then add it to the environment variable (this method is not recommended, because after solving this problem, there will be other problems later)

   3. Solution 2: downgrade selenium3 to selenium2 (will be introduced next)

 

3. Check the pip environment

    1. Open cmd, enter pip, and check whether the pip environment is normal

>>pip

    2. If the prompt: Did not provide a command appears when entering pip, it means that there is a problem with the pip environment. The temporary solution is to add the suffix pip.exe when entering pip. For the specific reasons, see the next solution.

Fourth, pip to view the selenium version number

    1. Open cmd and enter pip show selenium

>>pip show selenium

   2. Look at the version number display in the red area: 2.53.0, which shows the version number currently in use

(If you are showing the beginning of 3.0 here, you need the next steps)

Five, pip downgrade selenium

    1. In order to avoid conflicts with the previously installed selenium version, first find the selenium3.0 directory: python\Lib\site-packages directory

Just delete all the files that start with selenium. All third-party packages of python are under this directory.

     2. Open cmd and enter pip install selenium==2.53.6 (note that there are two ==, do not leave spaces in between, the version 2.53.6 is recommended here)

>>pip install selenium==2.53.6

 

Six, upgrade pip version

    1. If the words in the red area below appear during the use of pip, it means that the version of pip is too low, and it is recommended to upgrade

    2. How to upgrade pip? Look at the last sentence: python -m pip install --upgrade pip

 

   3. Just tap the corresponding prompts above.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325405154&siteId=291194637