Discovering a specific URL link element within the DOM using webdriver.io

I am currently utilizing webdriver io for conducting tests on a webpage. I am in need of verifying the existence of an element with a specific href on the page.

I have attempted to achieve this using the following

snippet

var client = webdriverio.remote(options);

     .elements('.mylinkclass', function(err,res) {
        res.value.forEach(function(elem){
                client.getText(elem).then(function(text) {
                if (text=="www.superweb.com"){
                   console.log("allright!");
                }
            })
        })

Answer №1

When writing your code, make sure to specify the exact element you want by using a CSS selector with the 'href' attribute value. This will ensure that you only select elements with the specified attribute:

client
.element("a[href='http://www.superweb.com']") // this will target specific 'a' elements with the given href attribute
.then(function(elem){
    console.log(elem); //element found!
})
.catch(function(err) {
    console.log("err", err); //will run if no elements match your URL
});

Consider using the link text selector for more targeted selection:

<a href="http://www.superweb.com">www.superweb.com</a>

client.getText('=www.superweb.com', function(err, text) {
    console.log(text);
});

For more information on selectors in webdriver, check out:

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

Creating a new route in a Express JS server to specifically handle POST requests

Just starting to learn the ropes of Javascript, and I'm diving into express to create an application that will enable users to craft new recipes, explore existing ones, and view details about each recipe. To get things moving, I've launched my s ...

Is there a way to adjust this angular2 service to make it slightly more synchronous?

My goal is to create an Angular2 service that performs the following tasks: FTP to a remote server Read certain lines from a file Create a 'results' JSON object and return it to the component that called the service I have successfully impleme ...

Tips for navigating through pagination indexes with Angular 6

Hey there, I'm currently working on a project where I need to automatically click through each pagination index. Initially, only the first index can be clicked. After that, the following page indexes are not clickable. Here's the code snippet: ...

How to utilize Safari driver in Selenium for positioning images

I'm attempting to capture a screenshot of a webpage, extract the size and position of an image, and then save that image to a file. Here is a snippet of code: this.driver.navigate().to(xxx); final byte[] arrScreen = ((TakesScreenshot) this.driver). ...

Disregard validation of the view if the element includes the attributes `display: none`

Displayed below is an HTML text input that is designed to toggle visibility using jQuery's slideUp and slideDown functions, which change the display attribute to none with animation. My current challenge is that I do not want to validate the element w ...

Steps to add npm peerDependencies for a warning-free installation

Stackoverflow has plenty of questions about npm peerDependencies warnings, but none specifically address the best practices for actually handling the dependencies. Should we save them along with our dependencies and devDependencies? If so, what is the purp ...

Navigating windows pop-ups in Selenium 2.0 (WebDriver): Best practices

enter code hereBrief : My current project involves using selenium 2.0 for automating UI testing, and everything was going smoothly until I encountered pop-ups. Now, I am faced with the challenge of handling windows popups. The issue at hand is that when I ...

Extract latitude and longitude data using Mapbox's autocomplete feature

Currently, I have integrated Mapbox with autocomplete in a Vue component: <template> <div> <div id='geocoder'></div> </div> </template> <script> import mapboxgl from 'mapbox-gl& ...

State loss occurs when moving to a different page using next/link

Currently, I am working on a library application with Next.js. Within this project, there are two main pages: BooksPage, which displays a list of all books, and BookPage, where detailed information about a specific book is shown. The components involved in ...

When the "change" event listener is added to an input element, the innerHTML is updated as the value increases but not when it decreases

My div block contains a value that I need to adjust as the input value changes. While the adjustment works when the input value increases, it does not change when the input value is decreased. It seems like there may be an oversight in my logic that I am m ...

How can I configure Selenium and Maven to run tests on a specific browser specified in the pom.xml file?

Including a parameter tag in the testng.xml file like this: <parameter name="browser" value="Firefox"></parameter> and using the following code: @Parameters({"browser"}) public void test(String browser){ ... } we can create a webdriver obj ...

An Error with jQuery Autocomplete: "Callback is not Defined"

I am currently working on a jQuery script that involves autocomplete and selecting the correct value on the client side. Here is my functional code without the selected value (it displays all username available in my JSON): $(function() { $( "#us ...

Selenium browser paired with a ReCaptcha feature

As I work on automating the process of navigating through multiple pages and filling out a form, I encounter a roadblock when reaching a Google ReCaptcha that requires manual solving. Despite my best efforts, every time I try to solve the ReCaptcha, I rece ...

I just obtained the height measurement of a dynamic table - now I must transfer this height value to a different element

Recently, I encountered a situation where I needed to get the height of a dynamic table using code like this: var table = document.getElementById("test"); document.write(table.offsetHeight); However, the challenge arose when I realized that I also needed ...

Is there a way to include a button at the top of the Notiflix.Loading() overlay for closing or stopping it?

I've integrated the "notiflix" library into my project, and I'm currently using notiflix.loading.pulse() for a lengthy process. While this works perfectly fine, I would like to add a button (for closing/stopping the process) on top of the loading ...

Design a custom screensaver using jQuery that includes a timed delay feature and an alert message

I am currently working on implementing a screensaver feature for my website. Here is the breakdown of what I am trying to achieve: When detecting the onload, clicks, and touches, I want to start a timer that counts 5 seconds. If any of these events are d ...

Is there a way to customize event property setters such as event.pageX in JavaScript?

Is there a way to bypass event.pageX and event.pageY for all events? This is because IE10+ has a known bug where it sometimes returns floating point positions instead of integers for pageX/Y. ...

Nightwatch.js custom assertion for array comparison fails to function as expected

Utilizing the nightwatch-cucumber framework, which is built on top of Nightwatch.js, I am in the process of creating automated end-to-end tests. As a newcomer to 'JavaScript' and 'node.js', I encountered an error during the execution of ...

Requesting Axios.get for the value of years on end

I'm grappling with obtaining a JSON file from the server. The endpoint requires a year parameter, which needs to be set as the current year number as its value (e.g., ?year=2019). Furthermore, I need to fetch data for the previous and upcoming years a ...

Ways to display the ping of a game server on your screen

Is there a way to display the game server's ping on the screen like in the example below? this.tfEnter.text = ShowPing + " ms"; Sometimes the code snippets provided in examples may not function properly. Channel List Image: https://i.stack ...