Anky
Anky

Reputation: 11

extract integer value from webelement and compare again using cypress

enter image description here

How to extract 3 from this and compare it with same if this integer value changes 3

Upvotes: 0

Views: 351

Answers (1)

Krishna Majgaonkar
Krishna Majgaonkar

Reputation: 1746

Easy ways to extract element text and compare it with expected value are:

cy.get(locatorOfElement).invoke("text").then((value) => {
    expect(value).to.equal("3");
});
cy.get(locatorOfElement).invoke("text").should("be.eq", "3");

and if you want to compare it with integer value then you have to convert the extracted value to an integer and then compare it to an expected integer value.

cy.get(locatorOfElement).invoke("text").then((value) => {
    expect(parseInt(value)).to.equal(3);
});
cy.get(locatorOfElement).invoke("text").then(parseInt).should('eq', 3)

Upvotes: 1

Related Questions