CodeceptJS
CodeceptJS copied to clipboard
Is it possible to work with element inside another element ?
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
It will be very nice to have such feature
Did you take a look at within ?
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))
}
})
}