0

Whenever I try to run this code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome()
browser.get("https://kahoot.it/") 
time.sleep(10)
code = browser.find_element_by_id("inputSession")
code.send_keys("273976")
login_attempt = browser.find_element_by_xpath("//*[@type='submit']")
login_attempt.submit()

I get the error

Traceback (most recent call last):
File "C:\Users\jiney\AppData\Local\Programs\Python\Python37- 
32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in 
start
stdin=PIPE)
File "C:\Users\jiney\AppData\Local\Programs\Python\Python37- 
32\lib\subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "C:\Users\jiney\AppData\Local\Programs\Python\Python37- 
32\lib\subprocess.py", line 1155, 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/jiney/AppData/Local/Programs/Python/Python37- 
32/kahootthing.py", line 4, in <module>
browser = webdriver.Chrome()
File "C:\Users\jiney\AppData\Local\Programs\Python\Python37-32\lib\site- 
packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\jiney\AppData\Local\Programs\Python\Python37-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: 'chromedriver' 
executable needs to be in PATH. Please see 
https://sites.google.com/a/chromium.org/chromedriver/home

if there is any help it would be greatly appreciated since it's pretty confusing, I think it's something to do with the modules but I've tried uninstalling and reinstalling twice.

Thanks!

2 Answers2

1

As the error shows:

executable needs to be in PATH

You should add the path:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome(executable_path=r'C:\the\path\to\chromedriver.exe')
browser.get("https://kahoot.it/") 
time.sleep(10)
code = browser.find_element_by_id("inputSession")
code.send_keys("273976")
login_attempt = browser.find_element_by_xpath("//*[@type='submit']")
login_attempt.submit()

Hope this helps you!

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
1

You're gonna have to install ChromeDriver and make it available in path.

Dmitry Yantsen
  • 1,145
  • 11
  • 24