Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Going through a list in Capybara?

I have a drop down menu. I want capybara to go through it and find the specific element and click on it. I'm currently trying to do a within clause and having it iterate through the list and find this element: "Cow_poop"

<li role="option" unselectable="on" title="Cow_poop" class="ant-select-dropdown-menu-item ant-select-dropdown-menu-item-selected" aria-selected="true" style="user-select: none;">Cow_pop</li>

This is the code that I'm trying to do.

find('div.ant-select-dropdown-menu-item-selected', text: 'Cow_poop').click

However it's giving me this error:

 Capybara::ElementNotFound:
       Unable to find css "div.ant-select-dropdown-menu-item-selected"
like image 592
Rubyman543 Avatar asked Sep 08 '26 12:09

Rubyman543


1 Answers

It's not a <div> but a <li> element.

Your effective line of code will be:

find('li.ant-select-dropdown-menu-item-selected', title: 'Cow_poop').click

Alternative:

find('li.ant-select-dropdown-menu-item-selected[title=Cow_poop]').click
like image 184
undetected Selenium Avatar answered Sep 10 '26 09:09

undetected Selenium



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!