4

So I have a table of 250 of rows, and I want to just get all the values from one column and check if they meet the required criteria:

const rows = browser.elements(selector..);
 const numbers = [];
 rows.value.forEach(cellData => {
 const value = browser.elementIdText(cellData.value.ELEMENT).value;
 // some logic to check if the value is ok
 numbers.push(value);
 });
 // check if all numbers are sorted correctly

, but it most of the time it fails on the line (it says stale element reference: element is not attached to the page document):

const value = browser.elementIdText(cellData.value.ELEMENT).value;

I tried doing cellDate.getText(), but there was a Java socket error, could someone help? I assume the selector is not attached to the page as indicated, but I can't figure my head out how to just loop through them all.

asked Feb 1, 2018 at 8:21
1

1 Answer 1

4

I had a solution similar to your method before and while it seems to work, I think there might just be some slight adjustments to your code to get what you want. I never had much luck chaining from the end of the elementIdText call.

Step 1: Grab all the Data (browser.elements or browser.$$):

let cellData = browser.$$('selector that matches desired Column Data') 

The above returns an array of JSON WebElements. And as you know you can correctly loop through the array looking at the "values". If you use the selector that matches the Column Values you're looking for you should have all similar data stored in the element.value.ELEMENT.

Step 2: Loop through the cellData array and pluck out the text values of the ELEMENT using browser.elementIdText()

cellData.forEach((elem) => {
 let number = browser.elementIdText(elem.value.ELEMENT)
 //elementIdText also returns a JSON WebElement so it's number.value
 if(number.value === <condition>) {
 console.log('number looks good')
 //perform other on value logic
 }
 })
 //perform other logic still in loop EX: array.push()
})

I hope this helps! Let me know if you hit any snags!

answered Feb 1, 2018 at 16:27
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.