Explain the significance of the symbols $$ and $ in the context of webdriver, and provide instructions on integrating them into

According to the webdriver documentation, using the $ and $$ functions in WebdriverIO can provide shortcuts for moving deeper into the DOM tree without relying on complex xPath selectors.

Currently, I am working on writing a cucumber test for my Reactjs application with Flowjs, utilizing web driver and chai. The UI design includes various buttons which need to be tested for existence along with their text/values. You can view the design here.

This is the approach I have taken:

const links = $$('.button').filter(function(link) {
  return link.isVisible();
});
const button1_value = links[0].getText();
const button2_value = links[1].getText();
expect(button1_value).to.equal('button1');
expect(button2_value).to.equal('button2');

However, I encountered an error when using $$. You can see the error message here.

Is there an alternative method to retrieve a list of buttons for testing purposes? Should I import $ and $$ for use in JavaScript files?

Answer №1

Ah, I understand now. We are able to utilize $$ and $ in conjunction with browser.

For example:

const links = await browser.$$(selector);

However, when retrieving the content or value of buttons, I implemented the following approach.

const links = await browser.getText('.button');
expect(links[0]).to.equal('button1');
expect(links[1]).to.equal('button2');

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

function embedded in velocity.js chain

How can I effectively execute this code? I keep encountering various errors. After the sequence is completed, I want to incorporate an additional function. I am utilizing jQuery in conjunction with velocity.js $(".close").click(function(){ var my ...

Updating React state for no apparent reason

My issue is quite straightforward. In my application, I have a user list stored in the state which is populated by a database call. Additionally, there is a selected user that gets filled when an element in the user list is clicked. Whenever a userlist e ...

The addScript feature seems to be experiencing difficulties upon the initial website load

Currently, I am utilizing the jquery.flexslider plugin and it is performing well. However, I have a specific requirement where I do not want to load the plugin for screens that are smaller than 600px. After experimenting with various scripts, I have final ...

Manipulating and filtering an array of objects in JavaScript/jQuery

Looking to simplify my array manipulation in Javascript, I need to subset based on key-value matches. I have an array called js_obj, and my goal is to modify objects where a certain condition is met. Consider the structure of my array: js_obj = [{ wo ...

Is there a way to verify that a form field has been completed?

Currently, I am grappling with a method to clear a field if a specific field is filled in and vice versa. This form identifies urgent care locations based on the information provided by users. The required entries include the name of the urgent care facil ...

"Exploring the best way to loop through multiple JSON data in a jQuery response

https://i.stack.imgur.com/O0F6g.pngMy JSON response contains multiple data points presented as follows. WellNames […] 0 {…} id 56 well_name AL HALL api 34005205550000 1 {…} id 498 well_name BONTRAGER api 34005233850000 2 {…} id 499 ...

Looking for guidance on restructuring a JSON object?

As I prepare to restructure a vast amount of JSON Object data for an upcoming summer class assignment, I am faced with the challenge of converting it into a more suitable format. Unfortunately, the current state of the data does not align with my requireme ...

Exploring the indexOf method in Jade

Currently using Jade and Express. '#{value.users}' is an array data type. '#{user.username}' is a string data type. Attempting to utilize the if '#{value.users}'.includes('#{user.username}') method. When true, I ...

Turning a string into JSON (encountering an unexpected token u/')

One burning question remains: why is this not functioning properly? It keeps throwing an 'unexpected token' error! var inquiry = "{'form_id':'foo','title':'bar'}"; console.log(JSON.parse(inquiry)); ...

The combination of Firebase and Next.js does not store data in the real-time database

I'm facing a major issue with the Firebase Realtime Database as it is not saving data. For instance, const createUserProfile = (email,user,username) => { console.log(email); console.log(user) const db = getDatabase(); console.log(db ...

When executing Selenium code alongside Locust, the statistical data for the Locust tool may not be visible

click here for image description view more images here We are currently experiencing an issue where the Locust tool Statistics data is not showing up when running selenium code with locust. Even though the script runs successfully, the data is not appea ...

Is there a way to set up Selenium so that Chrome already has an extension installed?

We are currently running a series of tests that utilize Selenium to generate Chrome instances when executed on a local system. These Chrome instances are created with basic, default profiles that have no extensions enabled. However, we are interested in po ...

Troubleshooting issues with hint functionality and fullscreen mode in CodeMirror within a jQuery layout

I have integrated the codeMirror library into the UI Layout Plug-in on my website. Challenges: When using CodeMirror within the layout, the Full Screen Editing feature does not work as intended. Press F-11 to zoom in and Esc to exit full screen mode. I ...

Instructions for sending an array of integers as an argument from JavaScript to Python

I have a JavaScript function that extracts the values of multiple checkboxes and stores them in an array: var selectedValues = $('.item:checked').map(function(){return parseInt($(this).attr('name'));}).get(); My goal is to pass this a ...

In the Android Chrome browser, the settings of the meta viewport attribute do not take effect when the device is in full screen mode

While using the fullscreen api in Android, I noticed that the values of meta viewport attributes like initial-scale and user-scalable are not reflected in the browser when in full screen mode. However, when not in full screen mode, these values work as exp ...

Tips for resolving the stale element reference error within my codebase

I keep encountering the Stale element error. Despite my attempts to resolve it, I have been unsuccessful so far. d.get("https://iaeme.com/ijciet/index.asp"); java.util.List<WebElement>link = d.findElements(By.className("lik")); for (int k=1 ; k< ...

Formik state is mysteriously reverting field values to their default state

I've encountered an issue with my form and song state while trying to add a new field called "appleMusicId". Unfortunately, every time I add this field, it seems to reset the values of timeDescription and sceneDescription. I've spent hours tryin ...

Modify iframe form action URL dynamically upon user visiting the URL with a specified parameter

Below you will find a code example: The page URL is: <html> <body> <h1>main page</h1> <iframe src="http://example2.com"> <form id="test" action="http://example3.com?id=1"> ... </form&g ...

Translating MySQL data into JavaScript using PHP

Hey everyone, I'm having trouble utilizing MySQL row values in JavaScript. Despite experimenting with various combinations of quotes and double-quotes. $sql = "SELECT desk_id, desk_x, desk_y FROM desks"; $result = $conn->query($sql); if ($result- ...

When nightwatch injects JavaScript, it fails to refocus on the subsequent element within the webpage

It's taking a long time to enter over 300 characters using nightwatch's setValue function since it keys in each character individually. I attempted to use the .execute function to inject custom JavaScript onto the page, and while the value is suc ...