selenium.common.exceptions.WebDriverException: Message: unknown command: 'Page.addScriptToEvalueteOnNewDcument' wasn't found
时间: 2023-11-23 12:56:25 浏览: 24
这个错误通常是由于Selenium版本不兼容导致的。在Selenium 4.0中,WebDriver API已经升级为W3C标准,而之前的非W3C标准API已被弃用。因此,如果您的代码使用了旧的非W3C标准API,就会出现这个错误。
解决这个问题的方法是升级您的代码以使用新的W3C标准API。如果您使用的是Selenium 3.x版本,则需要将代码升级到Selenium 4.0版本。如果您使用的是Selenium 4.0版本,则需要检查您的代码是否使用了旧的非W3C标准API,并将其替换为新的W3C标准API。
以下是一个使用新的W3C标准API的示例代码:
```python
from selenium import webdriver
driver = webdriver.Chrome()
# 使用新的W3C标准API来滚动到页面底部
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
```
相关问题
selenium.common.exceptions.WebDriverException: Message: unknown command: Page.addScriptToEvalueteOnNewDcument wasn t found
这个错误通常是由于Selenium版本不兼容导致的。在Selenium 4.0中,一些命令已被弃用或更改,因此旧版本的代码可能无法在新版本中正常工作。具体来说,错误信息中提到的命令“Page.addScriptToEvaluateOnNewDocument”已被弃用,因此需要使用新的命令“Page.addScriptToEvaluateOnNewDocumentOnLoad”来替换它。
以下是一个示例代码,演示如何使用新的命令来添加脚本:
```python
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--remote-debugging-port=9222')
driver = webdriver.Chrome(options=options)
driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocumentOnLoad', {
'source': 'console.log("Hello, world!");'
})
driver.get('https://www.google.com')
```
在这个示例中,我们使用了Selenium 4.0中的新命令“execute_cdp_cmd”来执行CDP(Chrome DevTools Protocol)命令。我们使用“Page.addScriptToEvaluateOnNewDocumentOnLoad”命令来添加一个简单的脚本,该脚本在每次加载新文档时都会运行,并在控制台中输出“Hello, world!”。
selenium.common.exceptions.WebDriverException: Message:
selenium.common.exceptions.WebDriverException: Message: Unexpected error launching Internet Explorer是一个selenium库中的异常,表示在启动Internet Explorer浏览器时遇到了意外错误。可能的原因是IE浏览器配置有问题或者缺少必要的驱动文件。
selenium.common.exceptions.WebDriverException: Message: ‘IEDriverServer.exe’ executable needs to be in PATH则表示在启动Internet Explorer浏览器时,系统找不到IEDriverServer.exe驱动文件。你需要下载并配置IE驱动文件,确保其在系统的PATH环境变量中。
driver = webdriver.Chrome(executable_path=r"D:\Anaconda3\file\envs\item\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe", options=options)这段代码是在使用Chrome浏览器时指定了ChromeDriver的路径。你需要确保路径中的chromedriver.exe文件存在,并且与你的Chrome浏览器版本相匹配。