Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试使用selenium运行脚本时出错_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python 尝试使用selenium运行脚本时出错

Python 尝试使用selenium运行脚本时出错,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,每当我尝试运行此代码时 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("27

每当我尝试运行此代码时

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()
我得到了错误

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
回溯(最近一次呼叫最后一次):
文件“C:\Users\jiney\AppData\Local\Programs\Python\Python37-
32\lib\site packages\selenium\webdriver\common\service.py”,第76行
开始
标准偏差=管道)
文件“C:\Users\jiney\AppData\Local\Programs\Python\Python37-
32\lib\subprocess.py”,第756行,在__
恢复信号,启动新会话)
文件“C:\Users\jiney\AppData\Local\Programs\Python\Python37-
32\lib\subprocess.py”,第1155行,在执行子进程中
startupinfo)
FileNotFoundError:[WinError 2]系统找不到指定的文件
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“C:/Users/jiney/AppData/Local/Programs/Python/Python37-
32/kahootthing.py“,第4行,in
browser=webdriver.Chrome()
文件“C:\Users\jiney\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\selenium\webdriver\chrome\webdriver.py”,第73行,在__
self.service.start()
文件“C:\Users\jiney\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\selenium\webdriver\common\service.py”,第83行,开始
os.path.basename(self.path)、self.start\u错误消息)
selenium.common.exceptions.WebDriverException:消息:“chromedriver”
可执行文件需要在路径中。请看
https://sites.google.com/a/chromium.org/chromedriver/home
如果有任何帮助,它将非常感谢,因为它相当混乱,我认为这是与模块有关,但我已经尝试卸载和重新安装两次

谢谢

如错误所示:

可执行文件需要在路径中

您应该添加路径:

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()
希望这对你有帮助

如错误所示:

可执行文件需要在路径中

您应该添加路径:

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()

希望这对你有帮助

您必须在path中安装并使其可用。

您必须在path中安装并使其可用