-1

I am trying to make a function that refreshes any page when given the URL. But the program won't run. What am I doing wrong? This is my code:

from selenium import webdriver
import time

def page_refresh(url):
    driver = webdriver.Firefox()
    driver.get(url)
    x = 0
    while x <= 5:
        time.localtime(10)
        driver.refresh(url)
    driver.close

page_refresh('https://www.wikipedia.org/')

This is what I get:

Traceback (most recent call last):
File "C:\Users\100453649\PycharmProjects\AutoRefresher\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\100453649\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\100453649\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, 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/100453649/PycharmProjects/AutoRefresher/Main.py", line 13, in <module>
page_refresh('https://www.wikipedia.org/')
File "C:/Users/100453649/PycharmProjects/AutoRefresher/Main.py", line 5, in page_refresh
driver = webdriver.Firefox()
File "C:\Users\100453649\PycharmProjects\AutoRefresher\venv\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 152, in __init__
self.service.start()
File "C:\Users\100453649\PycharmProjects\AutoRefresher\venv\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 
Heds
  • 9
  • The clue is in the last line of the exception. The gecko driver is not found. – lloyd May 07 '18 at 03:42
  • The last line in the stack trace defines your problem. The geckodriver cannot be started. It must be located in a directory that is included in the `PATH` variable, or you must define the path as a parameter to the webdriver when starting it. Have you installed the geckodriver? If so, where is it? Is that located in a directory defined in `PATH`? If so, are the permissions set so that the user running the program can start it (is executable)? – Ron Norris May 07 '18 at 03:43
  • Possible duplicate of [WebDriverException: 'geckodriver' executable needs to be in PATH even though it is](https://stackoverflow.com/questions/49947694/webdriverexception-geckodriver-executable-needs-to-be-in-path-even-though-it) – undetected Selenium May 07 '18 at 05:48

1 Answers1

0

Your Exception clearly says that

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Solution:

Add gecko driver path:

Example:

 from selenium import webdriver
 driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
 driver.get(url)
Magesh
  • 308
  • 1
  • 4
  • 18