user13933206
user13933206

Reputation:

Click on a element with specific text

Alright, I have a item which has this class class="country" and there are 12 elements with the same class. Now I want to get a element on its value. For example Italy. And now I want to click on a link in this item. The class of the link is class="link". So basically I want to click the link of the item with the name Italy

My code at the moment:

cy.get('.country').should('have.text', 'Italy').click();

HTML

<div class="countries">
   <div class="text">
      <h3></h3> 
      <div class="country">Italy</div> 
      <h4>Yala</h4> 
      <p>test</p>
      <a class="link" href="/mysite">Show details</a>
   </div>
</div>

Upvotes: 2

Views: 1602

Answers (1)

Fran&#231;ois
Fran&#231;ois

Reputation: 2200

Should() is an assertion and won't select the element you want. you probably want the contains() function.

cy.get('.country').contains('Italy').click()

Best

Upvotes: 1

Related Questions