Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
How to read/get the text of the element which is in <div> tag

I am new to cypress and Javascript, Please help me I wanted to read the text inside the tag and need to validate/assert that the text should be with the string "Saved" this div tag is the super child of <div role="row"...> tag

Below is the HTML code snippet

    <div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row ng-scope" ng-style="Viewport.rowStyle(rowRenderIndex)" ng-class="{'ui-grid-row-selected': row.isSelected}" style="">
      <div role="row" ui-grid-row="row" row-render-index="rowRenderIndex" class="ng-isolate-scope">
        <div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" ui-grid-one-bind-id-grid="rowRenderIndex + '-' + col.uid + '-cell'" class="ui-grid-cell ng-scope ui-grid-disable-selection ui-grid-coluiGrid-0009" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" role="gridcell" ui-grid-cell="" id="1634105595764-0-uiGrid-0009-cell">
          <div class="ui-grid-cell-contents ng-binding ng-scope">Saved</div></div>

But I am not able to get the element position, Please help me how to get the web element of the third div tag text

I used the above code but cypress throws an error

   cy.get(div).contains('Saved')

Expected to find element: #31 634108833080-0-uiGrid-0009-cell > .ui-grid-cell-contents, but never found it.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

In code example that you provided, is div some variable or what?

If I take your html snippet, load it with cypress and call cy.get('div').contains('Saved').should('exist') the test is successful.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can directly use contains and then check if the text exists or is visible.

cy.contains('.ui-grid-cell-contents', 'Saved').should('exist')
cy.contains('.ui-grid-cell-contents', 'Saved').should('be.visible')
about 4 years ago · Juan Pablo Isaza Denunciar

0

You are looking for the id at the end of the 3rd div, which has this expression

id="1634105595764-0-uiGrid-0009-cell"

but the error message has a 3 in front Expected to find element: #31 634108833080-0-uiGrid-0009-cell.

so have you added 3 in the front of the selector to get the third item?

Maybe you want

cy.get('div[role="gridcell"]')     // will give all cells
  .eq(2)                           // pick the 3rd cell (indexes start at 0)
  .contains('Saved')

or

cy.get('div[role="gridcell"]')     // will give all cells
  .eq(2)                           // pick the 3rd cell (indexes start at 0)
  .find('.ui-grid-cell-contents')
  .contains('Saved')

These give you the inner-most div. If you want the gridcell div instead, add .parent().

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda