how to setup selenium python environment for firefox?

倖福魔咒の 提交于 2019-12-06 01:57:45

问题


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.


回答1:


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

  1. install python (python3 already contains pip)
  2. install selenium (pip install selenium OR some IDEs like PyCharm propose to install libraries, just import selenium)
  3. download Mozilla webdriver
  4. enjoy!



回答2:


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:

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

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()



回答3:


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

2) then run pip install from command line: 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.




回答4:


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



来源:https://stackoverflow.com/questions/42204897/how-to-setup-selenium-python-environment-for-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!