javascript - WebdriverIO loop through element list - Stack Overflow

So I have a table of 250 of rows, and I want to just get all the values from one column and check if th

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.

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.

Share Improve this question edited Feb 1, 2018 at 8:43 Maciej Białorucki 5615 silver badges16 bronze badges asked Feb 1, 2018 at 8:21 Tomas EglinskasTomas Eglinskas 8553 gold badges12 silver badges25 bronze badges 1
  • You can get the idea here StaleElementReference Exception in PageFactory – undetected Selenium Commented Feb 1, 2018 at 15:11
Add a ment  | 

1 Answer 1

Reset to default 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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744638252a4585275.html

相关推荐

  • javascript - WebdriverIO loop through element list - Stack Overflow

    So I have a table of 250 of rows, and I want to just get all the values from one column and check if th

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信