Pawan Rai
Pawan Rai

Reputation: 681

Select option (choosen jquery) with cypress

Below is the code snippet of my cypress test.

cy.visit("https://harvesthq.github.io/chosen/");
cy.wait(4000);
cy.get('a.chosen-single').click();
cy.get('ul.chosen-results')
cy.get('li').first().click();

The following code visits the given link and opens the select option ( Choosen jquery plugin). But the code fails to select the option.

How can I select the option here ?

Upvotes: 0

Views: 204

Answers (1)

Frenchy
Frenchy

Reputation: 17027

a.chosen-single is not unique there are at least two descriptors: use cy.get('a.chosen-single:first').click(); or use id..

the two parts:

<div class="chosen-container chosen-container-single" title="" id="single_label_example_chosen" style="width: 350px;">
  <a class="chosen-single">
    <span>American Black Bear</span>
    <div><b></b></div>
  </a>

<div class="chosen-container chosen-container-single" title="" style="width: 95%;">
  <a class="chosen-single">
    <span>American Black Bear</span>
    <div><b></b></div>
  </a>

Upvotes: 1

Related Questions