CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Is it possible to work with element inside another element ?

Open LR-LR opened this issue 3 years ago • 3 comments

I am wondering if it is possible to work with elements inside of other elements.

For example :

const blocks = await Playwright._locate(blocksSelector);

for(let i = 0; i < blocks.length; i++) {
  const element = blocks[i]
  
  // How can i grab text for all h2 (or other selectors) inside element ?
  // Something like
  // let text = element.grabTextFrom('h2');
  // console.log(text)
}

The documentations only gives us example for element.click()

Thanks

LR-LR avatar Jan 22 '21 15:01 LR-LR

It will be very nice to have such feature

fasolens avatar Mar 19 '21 13:03 fasolens

Did you take a look at within ?

mkrtchian avatar Mar 19 '21 17:03 mkrtchian

Yes, I have looked at this. within doesn't take element as a parameter but locator. I'd like to have opportunity to get array of elements with const blocks = await Playwright._locate(blocksSelector);

And then use something like within:

for(let i = 0; i < blocks.length; i++) {
  const element = blocks[i]
  whithin(element, () => {
    ...
  })
}

What I am using currently and do the job is:

const selectorPattern = '//n2-data-table[@uniquekey="networkInterfaces"]//tbody//tr'
const rows_number = await I.grabNumberOfVisibleElements(selectorPattern)
for(let i = 1; i <= rows_number; i++) {
  I.grabTextFrom(locate(selectorPattern).at(i).find('td').at(6)).then((grabbedText) => {
    if (grabbedText === 'sometext') {
      I.checkOption(locate(selectorPattern).at(i).find('td').at(1))
    }
  })
}

fasolens avatar Mar 20 '21 10:03 fasolens