如何为firefox设置selenium python环境?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42204897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:23:15  来源:igfitidea点击:

how to setup selenium python environment for firefox?

pythonseleniumautomationselenium-firefoxdriver

提问by jaibalaji

How to setup selenium python environment for Firefox? I am using Firefox 50, selenium 3, python 3.5, I tried with many things binary and copying the geckodriver in environment path etc.

如何为 Firefox 设置 selenium python 环境?我正在使用 Firefox 50、selenium 3、python 3.5,我尝试了许多二进制文件并在环境路径中复制 geckodriver 等。

采纳答案by torina

As far as I understand, you want to develop in python, using selenium library and work with Firefox webdriver.

据我了解,您想在 python 中进行开发,使用 selenium 库并使用 Firefox webdriver。

  1. install python (python3 already contains pip)
  2. install selenium (pip install seleniumOR some IDEs like PyCharm propose to install libraries, just import selenium)
  3. download Mozilla webdriver
  4. enjoy!
  1. 安装python(python3已经包含pip)
  2. 安装 selenium(pip install selenium或者像 PyCharm 这样的一些 IDE 建议安装库,只需导入 selenium)
  3. 下载Mozilla 网络驱动程序
  4. 请享用!

回答by IslamTaha

The testing machine should have selenium V. 3.0.2, firefox V. 51.0.1 (Latest version) and geckodriver v. 0.14. If you are using linux please do the following steps:

测试机应有selenium V. 3.0.2、firefox V. 51.0.1(最新版本)和geckodriver v. 0.14。如果您使用的是 linux,请执行以下步骤:

[Look up the latest release on githuband replace the wget link with that. Downloading and installing an outdating release may result in "buggy" behaviour.]

[在 github 上查找最新版本并用它替换 wget 链接。下载和安装过时的版本可能会导致“错误”行为。]

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-vX.XX.0-linuxXX.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

To make sure that every thing is going well, check versions for all of them and make sure that its matching.

为确保一切顺利,请检查所有版本的版本并确保其匹配。

Here is an example to run

这是运行的示例

from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://google.com')
print driver.title
driver.quit()

回答by jaibalaji

1) in windows install python from : https://www.python.org/downloads/

1)在windows中安装python:https: //www.python.org/downloads/

2) then run pip install from command line: pip install selenium

2)然后从命令行运行pip install: pip install selenium

3) download gecko/chrome/ie driver & add driver.exe path to PATH Variable. so need to setup path while running selenium driver.Firefox() / driver.Chrome() method.

3) 下载 gecko/chrome/ie 驱动程序并将 driver.exe 路径添加到 PATH 变量。所以需要在运行 selenium driver.Firefox() / driver.Chrome() 方法时设置路径。

回答by Deepak Rao

driver = webdriver.Firefox()

Traceback (most recent call last):

回溯(最近一次调用最后一次):

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'

During handling of the above exception, another exception occurred:

在处理上述异常的过程中,又发生了一个异常:

Traceback (most recent call last):

回溯(最近一次调用最后一次):

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 can't get firefox

**** Ubuntu 18 无法获取 Firefox