Home > Software design >  Going through a dropbox in Capybara?
Going through a dropbox in Capybara?

Time:06-24

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"

    <div  role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-controls="7256666c-da5f-48d6-c8fc-a249a4ed0fc9" aria-expanded="false" tabindex="0">
      <div >
        <div  title="cow_poop" style="display: block; opacity: 1;">cow_poop</div>
        <div  style="display: none;">
          <div >
            <input autocomplete="off"  value="">
            <span >&nbsp;</span>
          </div>
        </div>
      </div>
      <span  unselectable="on" style="user-select: none;">
        <i aria-label="icon: down" >
          <svg viewBox="64 64 896 896" focusable="false"  data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true">
            <path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path>
          </svg>
        </i>
      </span>
    </div>

So in this html tag. I have a dropdown menu and I'm trying to select the value cow_poop. The way I'm currently doing it is this way.

    within('ant-select-selection') do
      find('cow_poop').click
    end

The problem with this method is that it's not working.

CodePudding user response:

. is missing before the class name, it should be within('.ant-select-selection')

You can also use:

within('.ant-select-selection') do
  find('div.ant-select-selection-selected-value', text: 'cow_poop').click
end

Alternative


find (:xpath, "//div[text()='cow_poop']").click
  • Related