Seeking the website URL for brand information from this website, I attempted to retrieve it using JavaScript in the console:
document.getElementById('phone_number').getElementsByTagName('a')[1].getAttribute('href')
However, my efforts with selenium-webdriver in JavaScript have been unsuccessful so far. The following is the code I am currently using:
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()
An error message that I encountered is as follows:
(node:24520) UnhandledPromiseRejectionWarning: TypeError: swd.By.css(...).getAttribute is not a function
I also tried:
await tab.findElement(swd.By.css('#phone_number a:nth-of-type(2)').getAttribute('href'))
Additionally, I experimented with this approach:
let website = await tab.findElement(swd.By.css('#phone_number').getText())
Unfortunately, I faced the same error and am unsure how to resolve it.