for the following html structure i want to extract 1 - 10 of 12 and keep only the last two characters of it, i.e. 12. How can I do this? I don't understand how to access elements or text without identifier.
<div class="paging-wrapper" xpath="1">
<div class="paging-label">
<!----><!----> 1 - 10 of 12 <!----><span>Text</span>
</div>
I first tried to output the text at all, but it only finds the text in the <span> and not the characters I actually want.
cy.xpath("//div[@class='paging-wrapper']//div[@class='paging-label']").then(($pageCounter) => {
const pageCount = $pageCounter.text()
cy.log(pageCount)
})
You can remove the span for the paging-label div and then just get the text for that div and slice the last 2 elements
$(".paging-label").find("span").remove()
$(".paging-label").text().trim().slice(-2) // Return 12
That should return 12 for the example that you mentioned
You can play around removing the span, save it in a variable, getting the value that you need, and then adding the span again to the paging-label div in case that you needed