How to set up Python 3 Selenium/Geckodriver for Firefox on Windows 10?

丶灬走出姿态 提交于 2019-12-11 00:26:37

问题


EDIT: Solved offsite. Put the details in the comment below. (Hope that's okay SO etiquette?)

Original post:

Saw a lot of people have had problems like this, but in all my searches I saw a lot of conflicting and confusing information that I didn't understand - this is all a bit out of my newbie depth.

I installed Selenium in PyCharm and was attempting to run this code from the book Automate The Boring Stuff with Python:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://inventwithpython.com')
linkElem = browser.find_element_by_link_text('Read It Online')
type(linkElem)
linkElem.click() # follows the "Read It Online" link

Running it throws the following exceptions:

Traceback (most recent call last):
File "C:\Users\LB\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\LB\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\LB\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/LB/Desktop/PythonProjects/AutomateTheBoringStuffProjects/generalTestingFile.py", line 2, in <module>
    browser = webdriver.Firefox()
  File "C:\Users\LB\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
    self.service.start()
  File "C:\Users\LB\AppData\Local\Programs\Python\Python36-32\lib\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. 

I've downloaded the latest geckodriver.exe (specifically the 64bit version since I'm on 64bit OS but I'm running 32bit Firefox if that's okay?), but I'm not sure where to put it.

I've looked up how to change a PATH but I don't know what exactly I'm supposed to change or where it's supposed to point to. (Firefox folders? Python folders?)

Any guidance would be appreciated!

来源:https://stackoverflow.com/questions/44088288/how-to-set-up-python-3-selenium-geckodriver-for-firefox-on-windows-10

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