首先是解决方案
正如 John Chen [Owner - WebDriver for Google Chrome] 昨天所承诺的那样,新版本的Chrome驱动程序 75.0.3770.90 and 76.0.3809.25已经发布,现在可以在Chrome驱动程序下载地点。这些版本包括与之前版本相比的以下错误修复Chrome驱动程序 75 and 76:
- 修复了 OSS 模式下错误拒绝 body 为空的 POST 请求的错误
- 添加了用于检索 Chrome 日志的新端点
另外,版本76.0.3809.25还包括以下更改:
- 在 W3C 模式下添加了 Is Displayed 命令的端点
电子邮件快照
Details
这将违背最佳实践关w3c
在 Chromedriver 中解决该错误:
Selenium::WebDriver::Error::UnknownCommandError:
unknown command: Cannot call non W3C standard command while in W3C mode
作为目前的实施Chrome驱动程序向客户端请求符合 W3C 的会话。
但是,此错误消息意味着Chrome驱动程序无法调用非W3C标准命令而在W3C mode在启动/产生新的网页浏览器 i.e. Chrome浏览器会议。
主要问题是,当Chrome驱动程序的客户请求符合 W3C 的会话,响应来自Chrome驱动程序不符合W3C规范,并导致语言API错误。
根据讨论W3C 模式下的 ChromeDriver 响应不符合标准John Chen(所有者 - Google Chrome 的 WebDriver)提及Simon Stewart(WebDriver 创建者)已更新:
-
w3c 会话的新会话响应应如下所示:
{
"value": {
"sessionId": "some-uuid",
"capabilities": {
"browserName": "chrome",
...
}
}
}
-
但是当开始一个新的会话时w3c
选项设置为true
in the chrome选项,返回的响应如下所示:
{
"sessionId": "af4656c27fb94485b7872e1fc616923a",
"status": "ok",
"value": {
"browserName": "chrome",
...
}
}
这既不是 JSON Wire Protocol 的正确形成的响应(其中“状态”将为整数),也不是正确形成的 W3C 响应,如果没有正确形成的响应,则无法使用 w3c 兼容。
This revision和这个commit解决了这个问题。
这个用例
想必您正在使用Chrome 驱动程序 v75.x with Chrome v75.x如果您仍然看到错误,您需要通过实验选项 w3c
as true
明确如下:
-
Ruby代码示例:
capabilities = { "chromeOptions" => {'w3c' => true} }
-
Java代码示例:
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class W3c {
public static void main(String[] args) throws Exception {
ChromeOptions opt = new ChromeOptions();
opt.setExperimentalOption("w3c", true);
ChromeDriver driver = new ChromeDriver(opt);
driver.get("https://www.google.co.in");
}
}
-
Python代码示例:
from selenium import webdriver
opt = webdriver.ChromeOptions()
opt.add_experimental_option('w3c', True)
driver = webdriver.Chrome(chrome_options=opt)
driver.get('https://www.google.co.in')
Update
Till Chrome 驱动程序 v74.x, Chrome and Chrome驱动程序组合默认在 w3c 模式下运行,但在chromedriver/server/http_handler.cc。根据详细信息goog:chromeOptions.w3c=false 不适用于正文为空的 POST 请求:
Method HttpHandler::HandleCommand
检查的值kW3CDefault
常量而不是会话goog:chromeOptions.w3c
价值。结果,JSON Wire 协议支持被破坏,其中允许带有空正文的 POST 请求。
JSON Wire 协议的需求将持续到displayed
端点在w3c模式下恢复。应该注意的是,W3C WebDriver 规范并不禁止使用“显示”端点,并且此功能在某些 API 中被积极使用。
As Is Element Displayed
命令不是 W3C 规范的一部分,但仍被某些 API 使用,并且其功能很难在这些 API 中复制。这更改列表 [revision and commit] 在 W3C 模式下重新启用此命令以轻松过渡到 W3C 模式。
@John 已经确认我们期待更新Chrome驱动程序v75.0明天修复。