selenium installation, error and resolve

The first step is to install selenium with a pip to download the module back.

The first step pip install

pip install selenium

Specific information is given as follows:

File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0b2-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 65, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0b2-py2.7.egg/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f753ad53390>> ignored

#  发现报错信息包含: Message: 'geckodriver' executable needs to be in PATH

Solution:
because of the lack dependencies geckodriver, so before you install selenium, first geckodriver the installation can be solved.

Windows System

  1. Download geckodriver.exe:

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

    Please choose to download according to system version; (such as Windows 64-bit systems)

  2. After download extract getckodriver.exe copied to the Firefox installation directory, such as (C: \ Program Files \ Mozilla Firefox), and add the path in the Path environment variable: C: \ Program Files \ Mozilla Firefox;

  3. After the restart cmd, you can run the code again

ubuntu16.04 system

  1. Download geckodriverckod Address: https://github.com/mozilla/geckodriver/releases

  2. After extracting geckodriverckod storage to / usr / local / bin / path to

Mac OS System:
If you have already installed the brew, then enter the following two commands to

brew install geckodriver
brew link geckodriver

Geckodriver test whether the installation was successful:

# shell窗口下输入命令
geckodriver

# 什么都不输出,也不退出,说明安装成功
# 注意:windows 系统需要重启一个新cmd窗口在输命令

Use pip listView installed modules:

discovery successfully installed.


The second step Python run Demo

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://www.baidu.com/')

Error:

Traceback (most recent call last):
  File "D:\programfiles\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "D:\programfiles\Anaconda3\lib\subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "D:\programfiles\Anaconda3\lib\subprocess.py", line 1155, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/code/commany/python/APPScan/main.py", line 7, in <module>
    browser = webdriver.Chrome()
  File "D:\programfiles\Anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "D:\programfiles\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Process finished with exit code 1

Chromedriver cause is not installed, refer to their own version of the browser chrome chromedriver corresponding version:
https://my.oschina.net/u/3367404/blog/3011400

chromedriver Download:
https://chromedriver.storage.googleapis.com/index.html

After the download is complete, the configuration ChromeDriver executable file to the environment variable.

If you are using Windows, the proposal directly drag chromedriver.exe file under the Python Scripts directory.

Run the script again, we found a new will pop up a new chrome:

Guess you like

Origin www.cnblogs.com/mysticbinary/p/11687618.html