我正在尝试使用chromedriver和w3c webdriver API启动Chromium会话,我向身体发送一个POST请求到http://localhost:9515/session
{
"capabilities": {
"alwaysMatch": {
"platformName": "linux",
"chrome:browserOptions": {
"binary": "/usr/bin/chromium",
"args": ["--start-page=about:blank"]
}
},
"firstMatch": [
{"browserName": "chrome"}
]
}
}
然后我得到了下一个回复
{
"sessionId": "b1a413df152017cd223dbabbcf1d2ffe",
"status": 33,
"value": {
"message": "session not created exception: Missing or invalid capabilities (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.14.47-1-MANJARO x86_64)"
}
}
哪些功能缺失或无效?
chromedriver(至少版本2.41)根本不支持W3C WebDriver API。
chromedriver所需的缺失能力是capabilities.alwaysMatch.goog:chromeOptions.w3c: true
,即
{“capabilities”:{“alwaysMatch”:{“goog:chromeOptions”:{“w3c”:true}}}}
这是chromedriver的缺陷。如果你想试验W3C WebDriver协议,你可以使用geckodriver
(firefox),它对W3C WebDriver API有近乎完美的支持。
Java代码:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("w3c", true);
new ChromeDriver(options);