In my scenario, the DOM structure is as follows:
<table id="campaigns">
<tr>
<th>Name</th>
<th>Status</th>
</tr>
<tr>
<td>first data</td>
</tr>
<tr data-id="1">
<td>intern test at Fri, 09 Dec 2016 03:12:26 GMT</td>
</tr>
<tr data-id="2">
<td>intern test at Fri, 09 Dec 2016 03:12:26 GMT</td>
</tr>
<tr data-id="3">
<td>intern test at Fri, 09 Dec 2016 03:12:26 GMT edit</td>
</tr>
<tr data-id="4">
<td>another data</td>
</tr>
<tr data-id="5">
<td>next data</td>
</tr>
</table>
When working with this in intern, I use the following code snippet:
this.remote
.findAllByXpath("//*[@id='campaigns']/tr"") // get all items from the list
.then(function (options) {
return Promise.all(options.map(function (option) {
return option.getVisibleText()
.then(function (text) {
if (text.includes("intern test")) {
option.click();
}
return text;
})
}))
})
My requirement is to click only on the text containing "intern test". However, a problem arises where after clicking the first element, the subsequent ones are also clicked causing stale elements.
How can I modify the code to stop the loop once the first matching element is found?
Any help would be greatly appreciated. Thank you!