Mr3*_*4r3 4 javascript selenium webdriver typeerror
我正在尝试使用 Javascript 和 Microsoft Edge 设置 selenium-webdriver 示例。在任何其他浏览器中,下面的代码都可以工作。但 Edge 不会启动。我试图找到解决方案,但找不到任何对我有帮助的东西......也许你可以提供帮助。
const {Builder, By, Key, until} = require('selenium-webdriver');
(async function example() {
let driver = await new Builder().forBrowser('MicrosoftEdge').build();
try {
await driver.get('http://www.google.com/ncr');
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
} finally {
await driver.quit();
}
})();
Run Code Online (Sandbox Code Playgroud)
这是 webdriver 的 npm 页面中最简单的示例。https://www.npmjs.com/package/selenium-webdriver
我收到以下错误:
[Running] node "c:\Users\mr\Desktop\Selenium\SeleniumToJS\test.js"
(node:3700) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'start' of null
(node:3700) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[Done] exited with code=0 in 0.512 seconds
Run Code Online (Sandbox Code Playgroud)
如果我插入“edge”而不是“MicrosoftEdge”,则返回:
[Running] node "c:\Users\mreinwald\Desktop\Selenium\SeleniumToJS\loginLogout.js"
(node:18112) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Do not know how to build driver: edge; did you forget to call usingServer(url)?
(node:18112) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[Done] exited with code=0 in 0.499 seconds
Run Code Online (Sandbox Code Playgroud)
此行触发错误:
new Builder().forBrowser('MicrosoftEdge').build();
Cannot read property 'start' of null实际上是说:“我不知道 MicrosoftEdge 是什么”。基本上,在某些情况下,selenium 需要以下之一:"firefox"、"edge"(而不是"MicrosoftEdge")、"chrome"等
现在
Do not know how to build driver: edge; did you forget to call usingServer(url)?
发生这种情况的原因有很多:
MicrosoftEdgeDriver在你的路径上吗?如果您对上述所有问题的回答都是肯定的,那么在幕后,在构建时,selenium 没有获得预期的功能,并且在最后一次尝试中,尝试连接到远程webDriver(这就是为什么它说usingServer)
因此,要解决这个问题,您可以尝试自己构建驱动程序,如下所示:
var edge = require('selenium-webdriver/edge');
var service = new edge.ServiceBuilder()
.setPort(55555)
.build();
var options = new edge.Options();
// configure browser options ...
var driver = edge.Driver.createSession(options, service);
Run Code Online (Sandbox Code Playgroud)
然后你可以继续driver.get('http://www.google.com/ncr');等等。
| 归档时间: |
|
| 查看次数: |
8151 次 |
| 最近记录: |