Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium-webdriver can't find the driver in 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);

Hello, I am constantly getting these errors, although I added the webdriver path in the system and I cant execute the test. Has anyone experienced something like that?

(node:15844) UnhandledPromiseRejectionWarning: Error: Do not know how to build driver: Firefox
(node:4764) UnhandledPromiseRejectionWarning: TypeError: Builder is not a constructor
like image 253
eda Avatar asked Dec 22 '25 03:12

eda


1 Answers

Got the same error "TypeError: Builder.forBrowser is not a constructor" for a sample code from any tutorial. Turns out they miss parenthesis after Builder. The correct code:

let driver = await new Builder().forBrowser('chrome').build();
like image 172
Alina Avatar answered Dec 23 '25 16:12

Alina