Selenium-WebDriver 在 JavaScript 中找不到驱动程序?


const {Builder, By, Key, util} = require("selenium-webdriver/Firefox");
async function example(){
let driver = await new Builder().forBrowser('Firefox').build();
await driver.get("https://www.google.com");
await driver.findElement(By.name("q")).sendKeys("Selenium", Key.RETURN);

你好 尽管我在系统中添加了Web驱动程序路径并且无法执行测试,但我不断收到这些错误。 有没有人经历过这样的事情?

(node:15844) UnhandledPromiseRejectionWarning: Error: Do not know how to build driver: Firefox
(node:4764) UnhandledPromiseRejectionWarning: TypeError: Builder is not a constructor

对于任何教程中的示例代码,都出现相同的错误"TypeError: Builder.forBrowser 不是构造函数"。原来他们在Builder之后错过了括号. 正确的代码:

let driver = await new Builder().forBrowser('chrome').build();

试试这个:

const {Builder, By, Key, util} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

最新更新