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

On the website mom.maison-objet.com/fr/marque/10008/rory-dobner-ltd?request_type=meeting#xtor=AL-1459, I’m trying to get the website url of the brand information which I can do in the console in JavaScript:

document.getElementById(‘phone_number’).getElementsByTagName(‘a’)[1].getAttribute(‘href’)

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("https://mom.maison-objet.com/fr/marque/10008/rory-dobner-ltd?request_type=meeting#xtor=AL-1459");

    await tab.sleep(3000);

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

}

main()

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