Hvaandres
Hvaandres

Reputation: 1005

How to access the right json value that is located through an array?

I'm currently using the fixture file to make sure it will be easier to call the right value.

 cy.fixture('latestLead.json').then(function (lead) {
            this.lead = lead
        })
My son file is the following:

{
  "status": 0,
  "result": {
    "totalSize": 1,
    "done": true,
    "records": [
      {
        "attributes": {
          "type": "Lead",
          "url": "/services/data/v51.0/sobjects/Lead/111111111"
        },
        "Id": "111111111",
        "Name": "Andres Latest Test"
      }
    ]
  }
}

The way that I'm trying to get the right value is the following:

cy.get(".gLFyf").type(this.lead.result.records.Id)

I'm able to get totalSize or done from the result object, but I'm not able to get any other value higher than that object. How can I get the Id value from the records Array?

Upvotes: 1

Views: 56

Answers (2)

Yevhen Laichenkov
Yevhen Laichenkov

Reputation: 8672

You can access an array item (in your case it's the object) using the index position (in your case it's zero)

cy.get(".gLFyf").type(this.lead.result.records[0].Id)

Upvotes: 2

Stevo
Stevo

Reputation: 343

try this cy.get(".gLFyf").type(this.lead.result.records[0].Id)

Upvotes: 1

Related Questions