Error message: "When using selenium-webdriver in JavaScript, the findElement method for <a> tags cannot be used as a function."&

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.

Answer №1

The problem arose when the function findElement was being used to call

.getAttribute('href')

Instead, it should have been moved outside of the method:

await tab.findElement(swd.By.css('#phone_number a:nth-of-type(2)')).getAttribute('href')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for customizing the background color of the MUI Menu Popover within a TextField that has the select property

In my quest to customize the appearance of a popover or menu in a TextField with the 'select' property, I referred to MUI customization docs for guidance. Successfully changing the text and label color of a TextField using the code below: const u ...

Utilizing NextJS Image Component in Conjunction with Auth0

I have been working on integrating auth0 with nextJS and encountered an issue with the next.js Image component. Let's review the code snippet: import Image from "next/image" import { useUser } from "@auth0/nextjs-auth0" export def ...

The pdf generation feature of pdf-creator-node in Linux seems to be malfunctioning

An error occurred with code EPIPE at afterWriteDispatched (internal/stream_base_commons.js:154:25) at writeGeneric (internal/stream_base_commons.js:145:3) at Socket._writeGeneric (net.js:784:11) at Socket._write (net.js:796:8) ...

Sliding elements horizontally with jQuery from right to left

I recently purchased a WordPress theme and I'm looking to customize the JavaScript behavior when the page loads. Currently, my titles animate from top to bottom but I want to change this behavior dynamically. You can view it in action here: I have ...

Explore all potentialities within an array of objects by examining and contrasting their key values

Looking to run a specific math formula with three parameters using an array of objects in JavaScript. The scenario involves sports, where there are three possibilities: Team A (win), Team B (win), or Draw. There are three different bet websites offering o ...

Encountering a connection issue with webdriver while working on a project in Netbeans platform

I've been encountering an issue while attempting to incorporate WebDriver in a Netbeans platform project. The error I keep running into is as follows: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolv ...

How can I use try-catch in JavaScript to call the same function again in the catch block

When encountering a scenario in JavaScript where a Try Catch block fails due to some issue, what is the best approach to handle this and retry the same operation until it is successful? For example: const getMyDetails = async()=>{ try{ await ge ...

Creating a Curved Border with Clip Path in CSS

Hey there! I'm currently attempting to add a speech bubble at the bottom left using clip-path, but I'm struggling to adjust the pixels just right to achieve the clear and exact look I want. Can someone provide suggestions on how to accomplish thi ...

A skeleton framework lacking a data storage backend

I am currently developing an offline javascript application that must be compatible with IE7, ruling out the use of localStorage. The app does not require any information persistence, as a refresh clears everything. My query is regarding setting up Backbo ...

Unraveling deeply nested array objects in JSON with Java Script/jQuery

I need help working with a JSON file that looks like the following: {[ {"name":"avc"}, {"name":"Anna"}, {"name":"Peter"}, {"Folder":[ {"name":"John"}, {"name":"Anna"}, {"Folder":[ {"name":"gg"}, ...

JavaScript error: You are trying to use Array.find() in Redux, but it

I am currently developing a react native application and I am using basic redux for managing the state, although I am a complete beginner to this. In a specific issue, I am facing an issue while fetching data from my redux store in the edit screen where th ...

Ways to troubleshoot the "TypeError: Cannot read property 'value' of null" issue in a ReactJS function

I keep encountering a TypeError: Cannot read property 'value' of null for this function and I'm struggling to pinpoint the source of the issue. Can someone help me figure out how to resolve this problem? By the way, this code is written in R ...

Error in sending data to the server via the specified URL: "Http failure response for http://localhost/post.php: 0 Unknown Error" and POST request to http://localhost/post.php failed with error code

Feeling a bit stuck trying to add data to my database. As a junior with PHP and Angular, I am using PHP via XAMPP and Angular 8. Is it possible to create separate files for the post and get methods in the PHP file? app.component.ts import { Component, O ...

"Apply a class to a span element using the onClick event handler in JavaScript

After tirelessly searching for a solution, I came across some answers that didn't quite fit my needs. I have multiple <span id="same-id-for-all-spans"></span> elements, each containing an <img> element. Now, I want to create a print ...

Using jqgrid to customize column header tooltips which are distinct from the actual column label

From what I gather, there are multiple methods for setting distinct column header tooltips. At the moment, my approach involves using jQuery's .attr() to set the tooltips. I'm curious if there is a more streamlined way to save the custom header ...

Exploring the process of clicking elements using WebDriverIO and Node.js with Selenium integration

After logging into my application, I am presented with multiple broadcast messages that may or may not appear. The number of messages is beyond my control. To dismiss each message and move to the next one, I must click on a checkbox and then on a next butt ...

Issue with dropdown element not triggering JavaScript onchange event

I am in the process of developing an application that involves searching a database and enabling users to compare the results. To achieve this, I require multiple dependent drop-down menus. While I have some understanding of HTML and PHP, my coding experti ...

What could be causing the slow web crawling of link clicks from a list of links in C#?

I am looking to automate the process of clicking on all links that contain the text "300". However, my current web-scraping code clicks each link individually which is quite slow. I have been storing the links in a list and then looping through them to cli ...

Is it possible to store data in a nested object using MongoDB?

I'm having trouble inserting the data from req.body into my mongodb collection. In this route, when the add method is triggered, I am attempting to create a query that will store the data from req.body in a nested collection array. router.post(&apos ...

Unable to play GSM extension files on a web browser due to compatibility issues

I've been attempting to play an audio file with a (.gsm) extension using <audio>, object tags, and JavaScript. <script> var myAudio = new Audio(); // creating the audio object myAudio.src = "test.gsm"; // assigning the audio file t ...