Python Selenium ChromeDriver文件找不到错误求助
Hey there! Let's break down what's going wrong with your Kahoot script and fix it step by step.
1. Why You're Getting the FileNotFoundError
The core issue is how you're setting up ChromeDriver:
You’re using
os.chdir()incorrectly — this function is meant to switch your working directory to a folder, not point directly to an executable file likechromedriver_win32.exe. When you pass the full .exe path toos.chdir(), Python tries to treat that file as a directory (which it isn’t), hence the error.
Even if you added ChromeDriver to your system PATH, your code wasn’t leveraging that correctly anyway.
2. Fixing the ChromeDriver Setup
You’ve got two simple options here, depending on your preference:
Option 1: Use ChromeDriver from System PATH (Recommended)
Since you confirmed ChromeDriver is in your system PATH, you don’t need to specify any path at all. Just initialize the Chrome driver directly:
browser = webdriver.Chrome()
Option 2: Directly Specify the ChromeDriver Executable Path
If you still want to hardcode the path (for clarity), skip os.chdir() and pass the .exe path directly to the Chrome driver:
browser = webdriver.Chrome(executable_path=r'C:\WebDriver\bin\chromedriver_win32.exe')
(Note: For Selenium 4+, the executable_path parameter is deprecated — you’d use Service instead, but since you’re on Python 3.6, this older syntax should work fine.)
3. Other Small Fixes for Your Script
There are a couple of other minor issues that might trip you up:
- Broken import statement: Your first two imports are on the same line — split them into separate lines for valid syntax:
from selenium import webdriver from selenium.webdriver.common.keys import Keys import os - Unreliable button click: The
Enter_Press()function usesfind_element_by_name("Enter"), but Kahoot’s submit button doesn’t actually have aname="Enter"attribute. Instead, useKeys.ENTERon the input fields (more reliable) or target the button via XPath.
Full Fixed Script
Here’s the complete, working version of your script with all fixes applied:
from selenium import webdriver from selenium.webdriver.common.keys import Keys import os Game_Pin = input('Enter your PIN: ') NickNAME = input('Enter your nickname: ') def Kahoot_Spammer(Game_Pin, NickNAME): # Use this line if ChromeDriver is in your system PATH browser = webdriver.Chrome() # OR uncomment this line to specify the path directly # browser = webdriver.Chrome(executable_path=r'C:\WebDriver\bin\chromedriver_win32.exe') browser.get('https://kahoot.it/') # Add a short wait to let the page load (prevents "element not found" errors) browser.implicitly_wait(1) # Enter and submit Game PIN game_pin = browser.find_element_by_id("Game PIN") game_pin.send_keys(Game_Pin) game_pin.send_keys(Keys.ENTER) # Wait for the nickname screen to load browser.implicitly_wait(1) # Enter and submit Nickname Name = browser.find_element_by_id("Nickname") Name.send_keys(NickNAME) Name.send_keys(Keys.ENTER) Kahoot_Spammer(Game_Pin, NickNAME)
Give this a try — it should resolve the FileNotFoundError and work as expected for joining Kahoot games automatically.
内容的提问来源于stack exchange,提问作者Golden Matrices

