Selenium

 

 1. 在Python中安装第三方库

1)安装Selenium

通过pip安装 

 

2). 下载geckodriverckod

从selenium3开始,webdriver/firefox/webdriver.py的__init__中,executable_path="geckodriver";而之前是executable_path="wires"。所有需要下载geckodriver。

1、下载 geckodriverckod 地址: https://github.com/mozilla/geckodriver/releases

2、解压后将geckodriverckod可以存放在任意路径,在使用webdriver时指明路径就行。

例如:

将geckodriverckod放在/usr/local/bin/下,

driver = webdriver.Firefox(executable_path = "/usr/local/bin/geckodriver")

如果没有下载geckodriverckod或是没有指明geckodriverckod的路径,执行执行程序会报错,如下:

 

Traceback (most recent call last):

  File "/Users/evan/evan/Eclipse/Selenium/src/Selenium_learn/learn_1.py", line 14, in <module>

    driver = webdriver.Firefox()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 144, in __init__

    self.service.start()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 81, in start

    os.path.basename(self.path), self.start_error_message)

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

 

 

 

 

 

 

2. 安装Selenium IDE

Selenium IDE的最后一个版本release在2015.3.15,所以,如果你安装的是最新的Firefox版本,会遇见与Selenimu IDE不兼容的问题。

解决方案:下载可以兼容的历史版本。

通过查看selenium IDE的note,发现它只支持这些版本

Works with Firefox 17.0 - 34.*        

历史版本下载路径:http://ftp.mozilla.org/pub/mozilla.org//firefox/releases/
上面有每个历史版本(包括不同平台,不同语言的),

zh-cn 表示中文简体

原文地址:https://www.cnblogs.com/gforc/p/7391234.html