带有 Edge TypeError 的 Javascript Selenium Webdriver:无法读取 null 的属性“start" [英] Javascript Selenium Webdriver with Edge TypeError: Cannot read property 'start' of null

查看:50
本文介绍了带有 Edge TypeError 的 Javascript Selenium Webdriver:无法读取 null 的属性“start"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Javascript 和 Microsoft Edge 设置 selenium-webdriver 示例.在任何其他浏览器中,以下代码都有效.但是Edge不会启动.我试图找到解决方案,但找不到任何对我有帮助的东西...也许你可以提供帮助.

I'm trying to set up selenium-webdriver example using Javascript and Microsoft Edge. In any other browser this code below works. But Edge won't start. I tried to find a solution, but couldnt find anything that helped me... Maybe you can help.

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

这是来自 webdriver 的 npm-page 的最简单示例.https://www.npmjs.com/package/selenium-webdriver

Its to easiest example from the webdriver's npm-page. 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

如果我插入 'edge' 而不是 'MicrosoftEdge' 以下返回:

If I insert 'edge' instead of 'MicrosoftEdge' follwing returns:

[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

推荐答案

此行触发错误:

new Builder().forBrowser('MicrosoftEdge').build();

Cannot read property 'start' of null 实际上说:我不知道 MicrosoftEdge 是什么".基本上,在某些情况下,selenium 需要以下之一:"firefox""edge"(而不是 "MicrosoftEdge")、"chrome"

Cannot read property 'start' of null actually says: "I don't know what MicrosoftEdge is". Basically, in some instances, selenium expects one of: "firefox", "edge" (instead of "MicrosoftEdge"), "chrome", etc

现在

不知道怎么建驱动:edge;你忘记调用 usingServer(url) 了吗?

发生这种情况的原因有很多:

This can happen due to many reasons:

  1. 是否安装了 Edge?
  2. 您有最新的 MicrosoftEdgeDriver 服务器吗?
  3. MicrosoftEdgeDriver 是否在您的 PATH 上?
  1. Is edge installed?
  2. Do you have the latest MicrosoftEdgeDriver server.?
  3. Is MicrosoftEdgeDriver is on your PATH?

如果你对以上所有回答都是肯定的,那么在幕后,在构建时,selenium 没有获得预期的功能,最后一次尝试连接到远程 webDriver (这就是为什么它说 usingServer)

If you answer yes to all of the above, then behind the scenes, while building, selenium didn't get the expected capabilities, and, for a last attempt, tries to connect to a remote webDriver (that's why it says usingServer)

因此,要解决此问题,您可以尝试自己构建驱动程序,如下所示:

As such, to solve this, you can try building the driver yourself, like this:

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

然后您可以继续使用 driver.get('http://www.google.com/ncr');

And then you can continue with driver.get('http://www.google.com/ncr'); etc.

这篇关于带有 Edge TypeError 的 Javascript Selenium Webdriver:无法读取 null 的属性“start"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆