Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
Javascript: fetch text and cut off

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)
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda