Tips for retrieving text from an element that is nested within an element's promise in Appium

Here's a snippet of code I'm working with:

const wd = require('wd')
const driver = await wd.promiseChainRemote("http://localhost:4723/wd/hub")
elements = await driver.elementsByAccessibilityId("commonElementsId")

I have received a promise object, and now I'm wondering how to retrieve a single element to apply the text() method and get the inner text. I found a solution in Java, but I need help translating it to Javascript. The Java code looks like this:

elements.get(indexOfElement).getText()

Unfortunately, this won't work in JavaScript. Any suggestions?

Answer №1

If you want to retrieve the text of all items in a list, make sure to iterate through each item

itemsList = await driver.elementsByAccessibilityId("uniqueElementsId")
for (index = 0; index < itemsList.length; index++) {
    console.log(itemsList[index].text())
}

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

Experiencing issues in retrieving data post-login using ASP.net session key method

I have developed a website using AngularJS for the front-end and Windows webforms for the back-end. I believe that the Authorization process is carried out using ASP.net Session Key. The approach involves creating an AngularJS Post method for "login" foll ...

How to boost the value of a property within a MongoDB document with Mongoose

Recently, I've been dealing with an array of objects named "items". This array includes different objects and I need to search for each object in MongoDB using the "baseId" found in the Base Document. Once I locate the matching object, I aim to update ...

waiting for elements in Nightwatch.js using FluentWait

I am seeking assistance on implementing FluentWait using nightwatch.js. How can I achieve this? Within my project, I have a global.js file that includes: waitForConditionPollInterval : 300, waitForConditionTimeout : 5000, However, it seems like this ...

Can anyone recommend a super sleek drop-down navigation menu that includes both images and text descriptions?

My interest has been piqued on how to create a menu similar to the one on with all the images and text details. Does anyone have any insights on the technologies utilized for this? Are there any commercial options available that offer a similar functiona ...

The driver is currently being downloaded and a new error has popped up for the second time

Greetings to all! Here is the Selenium automation code using Python that previously worked on Ubuntu OS. However, after installing Mint Linux, PyCharm, and downloading the code from GitHub, I encountered some issues. The first time I ran it in the new envi ...

Uniform Image Sizes in Bootstrap Carousel (With One Exception)

I am encountering a JavaScript exception related to image size. I am trying to set a fixed size for the images in my carousel, allowing them to auto adjust or resize without concern for distortion or pixelation. I have experimented with max-width and widt ...

Setting a JavaScript value for a property in an MVC model

I am currently working on an asp.net mvc application and I am in the process of implementing image uploading functionality. Below is the code for the image upload function: $(document).ready(function () { TableDatatablesEditable.init(); ...

Implement the use of `require` to update the `$watch` in an

As a new Angular user, I am facing an issue that involves having two directives in my HTML code like this: <parent-dir param="par"> <child-dir></child-dir> </parent-dir> And defining them in my JavaScript code as follows: In t ...

learning how to combine two json arrays of objects and showcase them in a react component

What is the best way to combine this data and present it in a table with a map using React? The text will be in the first column and the count in the second. const handleSubmit = async (event) => { event.preventDefault(); let URL1 = " ...

Need a jQuery callback function in PHP that only retrieves the value without any redirection

Initially, I expected this task to be simple but it turns out my skills are a bit rusty. The snippet of javascript/jquery code that I am using is: $.get("plugin.php", {up_vote:surl}, function(data){ //alert(data); document.getElementById(&apo ...

Tips for utilizing the window object in Angular 7

To implement the scrollTo() function of the window object directly, we can use window.scrollTo(0,0). However, when researching how to do this in Angular, I found that many people create a provider as shown below: import {InjectionToken, FactoryProvider} f ...

Extract information from a JSON string using a foreach loop to handle multiple occurrences of the same data type

I am working with a JSON object that I need to parse in order to retrieve specific data. The structure is as follows: "id": "5019b4b40cd8a056446b8eb4", "checkItemStates": [ { "idCheckItem": "xxxxxxxx", "state": "complete" }, { "idCheckItem ...

Leveraging a VueJS prop as a variable in an array mapping operation

Trying to figure out a solution where a variable (prop) can be used in an array map function. The initial code snippet looks like this: var result = this.$store.getters['example/store'].map(a => a.fixed_column) I aim for fixed_column to be ...

Disabling Navigation with Arrow Keys in Prettyphoto

Is there a way to prevent arrow keys from functioning in PrettyPhoto for a specific instance? I have tried using keyboard_shortcuts:false, but it still reloads the frame if left or right arrow keys are pressed, causing the form inside to reset. However, co ...

Error 500: An invalid data type was encountered in an express.js node.js environment

Currently, I am in the process of developing an Authentication page using a combination of node.js, express.js, and mysql2. The user ID and password entered on the webpage are then passed through app.post('/login',...). However, upon submitting t ...

Adjust the vertical alignment of an HTML element

I've been trying to make an image move using the variable counter, but for some reason, it's not working. If I set document.getElementById("movee").style.top directly to a number, it works fine. Combining it with the counter variable should theor ...

Troubleshooting Navigation Bar Toggle Button Issue in Bootstrap 5

Currently, I am in the process of working on a web project that requires the implementation of a responsive sidebar. This sidebar should be toggleable using a button located in the navigation bar. My choice for the layout is Bootstrap, and I have come acr ...

What is the best way to print the contents of an HTML element to the console in JavaScript?

I need to display the phrase "Jingle All the Way [Family Fun Edition] [DVD] [1996]" on the console from this Best Buy link. I am using axios and cheerio for this task. (async () =>{ const { data } = await axios.get(productUrl); const $ = cheerio.l ...

What is the best way to style the currently selected option element in a select dropdown?

I am trying to change the font color of specific option elements within a select dropdown by adding style="color: #D4D4D4". When I apply this style directly to an option element like <option value="TEST" style="color: #D4D4D4">TEST</option>, it ...

My goal is to retrieve all the links from a website and systematically click on each one

My goal is to fetch all the links from a website and then click on each one individually. However, when I run the code below, I am able to retrieve the total count of links correctly but I encounter a `null pointer exception` when trying to navigate to the ...