You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 like chromedriver_win32.exe. When you pass the full .exe path to os.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:

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 uses find_element_by_name("Enter"), but Kahoot’s submit button doesn’t actually have a name="Enter" attribute. Instead, use Keys.ENTER on 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:08:38