1

I haven't programmed in years. I am trying to learn to automate a task for work. I was able to successfully install selenium for Python after having some issues.

This is the simple program I am trying to test to make sure my installation was successful.

Note - I was having issues installing selenium so I had to set the path and some other stuff. So I'm thinking some of those changes might have affected running this Python program.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

When I run the program on the command prompt this is what I get.

>py main.py
Traceback (most recent call last):
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
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\jonab\Documents\Python Projects\Amazon SC Review Automation\main.py", line 4, in <module>
    driver = webdriver.Firefox()
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
    self.service.start()
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

I did reference this post and ran their code but got a different error. Python Selenium Traceback (most recent call last):

JCode
  • 48
  • 6
  • Are you sure your geckodriver is in PATH. – Arundeep Chohan Dec 31 '20 at 20:09
  • `geckodriver` needs to be downloaded separately and then the folder where you've saved it needs to be placed in your PATH environment variable. –  Dec 31 '20 at 20:10
  • From a Command Prompt, type `where geckodriver`. If you've placed said file in a folder included in your system's PATH environment variable, then you should see the full path to it. Otherwise, you'll get "INFO: Could not find files for the given pattern(s)." –  Dec 31 '20 at 20:15
  • @JustinEzequiel INFO: `Could not find files for the given pattern(s)` is what I'm getting. I downloaded the Windows 64 version from https://github.com/mozilla/geckodriver/releases I run exe file I only see the following message `1609446253348 geckodriver INFO Listening on 127.0.0.1:4444` – JCode Dec 31 '20 at 20:27
  • You're not supposed to run that yourself. Selenium would run that for you if it could find where you've saved it. Hence the repeated mention of the PATH environment variable. –  Dec 31 '20 at 20:45
  • @JustinEzequiel so I would just leave it in the downloads folder? It doesn't go anywhere specific? How do I know what path it's on? – JCode Jan 03 '21 at 02:34
  • I put the EXE file exactly where the main Python file folder I am running. It looks like it's working. Thanks. – JCode Jan 03 '21 at 02:49

0 Answers0