selenium-webdriver – JavaScript, findElement a href, is not a function

On the website, I’m trying to get the website url of the brand information which I can do in the console in JavaScript:


But with the selenium-webdriver in JavaScript, I can’t seem to find it. Here is my code:

let swd = require("selenium-webdriver");
let browser = new swd.Builder();
let tab = browser.setChromeOptions().forBrowser("chrome").build();

async function main() {

    await tab.manage().setTimeouts({ implicit: 10000 })

    await tab.get("");

    await tab.sleep(3000);

    let website = await tab.findElement(swd.By.css('#phone_number a::nth-child(2)').getAttribute('href'))



I’m getting this error:

(node:24520) UnhandledPromiseRejectionWarning: TypeError: swd.By.css(…).getAttribute is not a function

I try to simplify my code with:

let website = await tab.findElement(swd.By.css('#phone_number').getText())

But I get the same error and I don’t know how to solve it.

Read more here: Source link