如何为Firefox设置selenium python环境?我正在使用Firefox 50,selenium 3,python 3.5,我尝试了很多二进制文件并在环境路径中复制geckodriver等。
答案 0 :(得分:11)
试验机应具有硒V. 3.0.2,firefox V. 51.0.1(最新版本)和geckodriver v.0.14。如果您使用的是linux,请执行以下步骤:
apt-get update
apt-get install firefox
pip3 install selenium==3.0.2
wget https://github.com/mozilla/geckodriver/releases/download/v0.14.0/geckodriver-v0.14.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz && tar -C /opt -xzf /tmp/geckodriver.tar.gz && chmod 755 /opt/geckodriver && ln -fs /opt/geckodriver /usr/bin/geckodriver && ln -fs /opt/geckodriver /usr/local/bin/geckodriver
为确保每件事情都顺利进行,请检查所有内容的版本,并确保其匹配。
以下是运行
的示例from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://google.com')
print driver.title
driver.quit()
答案 1 :(得分:4)
据我所知,你想在python中开发,使用selenium库并使用Firefox webdriver。
pip install selenium
或某些IDE,如PyCharm建议安装库,只需导入selenium)答案 2 :(得分:0)
1)在Windows中安装python:https://www.python.org/downloads/
2)然后从命令行运行pip install:pip install selenium
3)下载gecko / chrome / ie driver&将driver.exe路径添加到PATH变量。所以需要在运行selenium driver.Firefox()/ driver.Chrome()方法时设置路径。
答案 3 :(得分:0)
driver = webdriver.Firefox()
回溯(最近通话最近一次):
File "/home/deepu/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver'
在处理上述异常期间,发生了另一个异常:
回溯(最近通话最近一次):
File "<stdin>", line 1, in <module>
File "/home/deepu/.local/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
self.service.start()
File "/home/deepu/.local/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.
**** Ubuntu 18无法使用Firefox