I'm trying out selenium's Simple Usage. Its code driver = webdriver.Firefox() gave an error.
This is my full code:
while True:
    try:
        from selenium import webdriver
        from selenium.webdriver.common.keys import Keys
    except:
        print('Failed to import selenium tools, retrying...')
        continue
    else:
        print('Selenium import success!')
        break
while True:
    try:
        browser = webdriver.Firefox()
    except:
        print('Open browser error: An error occured, retrying..')
        continue
    else:
        print('Success!')
        break
browser.get('http://www.python.org')
assert "Python" in browser.title
elem = browser.find_element_by_name('q')
elem.send_keys('pycon')
elem.send_keys(Keys.RETURN)
assert "No results found" not in browser.page_source
and the result:
Selenium import success!
Open browser error: An error occured, retrying..Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\user\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 "D:\code\python project\auto.py", line 14, in <module>
    browser = webdriver.Firefox()
  File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
    self.service.start()
  File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\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. 
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "D:\code\python project\auto.py", line 16, in <module>
    print('Open browser error: An error occured, retrying..')
The Selenium import success! result indicates that there is no problem during importing. On the other hand, browser = webdriver.Firefox() is the one causing problem.
How should I change it to make it work? Note: The file I am working on it called auto.py
 
     
     
     
    