mtbpecas
mtbpecas

Reputation: 13

Get dynamic id attribute value from an element

I need to check if a text value is displayed into a dynamic field after expand the row.

I paste part of the code where the info is displayed. For the following code I have 10 rows in the screen with different IDs. Post a screenshot with code, to not loose the code formatting. Step by step of the text.

  1. file name cypress.png
  2. expand first row and check if the file name is displayed at attribute value for the dynamic field
  3. If name not find in first row, expand next and check until find it.

New question: How can I get the value attribute to compare it with the name of the file uploaded? I try to use invoke(attr, value) but it does not work.

<div class="bx--text-input__field-outer-wrapper">
  <div class="bx--text-input__field-wrapper">
    <input id="scenario-name-63add9a59b4cb45bc67d7bab" 
      type="text" 
      class="bx--text-input bx--form-item" 
      readonly="" 
      value="cypress1.png">
  </div>
</div>

The issue is the id of the field that is dynamic. I am able to list all the ids using the cypress code below.

//Expand all rows -** I know about multiple click but the idea is to use this block to do the loop**
        
cy.get('.bx--table-expand__svg')
  .each(function($expand){
    cy.wrap($expand).click()
  })

**//Here I can list the id for each row, but I cant get the text for attribue value.**

cy.get('input[id*=scenario-]')
  .each(function($scn,index,$scenarios){
    cy.log($scn,index)
  })
           
**//I try to use INVOKE, but it gets char by char e not the entire value.


Upvotes: 0

Views: 174

Answers (1)

Paolo
Paolo

Reputation: 5451

//Here I can list the id for each row, but I cant get the text for attribue value.

There's a jQuery function that will do this

cy.get('input[id*=scenario-]')
  .each(function($scn) {
    const id = $scn.attr('id')
    console.log('Exact id is: ', id)
  })

Upvotes: 1

Related Questions