Filipm64
Filipm64

Reputation: 47

How can I get value of attribute

how can i get value from attribute and if the value == something then do ... In my particular case I want to get value from attribute and if the value is not EN then change language.

I tried:

if(cy.get('.language-menu').should('have.attr', 'language', 'EN')){
    //Language is English, do nothing
}else{
    //Language is not English, click button and change language
}

But this throws me an error when language is not english.

Thanks for your time.

Upvotes: 0

Views: 70

Answers (1)

Alapan Das
Alapan Das

Reputation: 18574

You can do something like:

cy.get('.language-menu').then(($ele) => {
    if ($ele.attr('language') == "EN") {
        //Language is English, do nothing
    } else {
        //Language is not English, click button and change language
    }
})

Upvotes: 3

Related Questions