我正在尝试使用 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();
}
})();
这是网络驱动程序的 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”,则返回:
[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 ”
等
现在
主题:
不知道如何构建驱动程序:edge;你忘记调用 usingServer(url) 了吗?
发生这种情况的原因有很多:
- 是否安装了 edge?
- 你有最新的MicrosoftEdgeDriver吗?服务器。?
MicrosoftEdgeDriver
是否在您的 PATH 上?
如果您对以上所有问题的回答都是肯定的,那么在幕后,在构建时,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);
然后您可以继续 driver.get('http://www.google.com/ncr');
等
关于带有边缘类型错误 : Cannot read property 'start' of null 的 Javascript Selenium Webdriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48577924/