正在浏览水豚的保管箱?

Rub*_*543 0 ruby selenium rspec ruby-on-rails capybara

我有一个下拉菜单。我希望水豚浏览它并找到特定元素并单击它。我目前正在尝试执行一个 inside 子句,并让它遍历列表并找到这个元素:“Cow_poop”

    <div class="ant-select-selection ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-controls="7256666c-da5f-48d6-c8fc-a249a4ed0fc9" aria-expanded="false" tabindex="0">
      <div class="ant-select-selection__rendered">
        <div class="ant-select-selection-selected-value" title="cow_poop" style="display: block; opacity: 1;">cow_poop</div>
        <div class="ant-select-search ant-select-search--inline" style="display: none;">
          <div class="ant-select-search__field__wrap">
            <input autocomplete="off" class="ant-select-search__field" value="">
            <span class="ant-select-search__field__mirror">&nbsp;</span>
          </div>
        </div>
      </div>
      <span class="ant-select-arrow" unselectable="on" style="user-select: none;">
        <i aria-label="icon: down" class="anticon anticon-down ant-select-arrow-icon">
          <svg viewBox="64 64 896 896" focusable="false" class="" 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>
Run Code Online (Sandbox Code Playgroud)

所以在这个html标签中。我有一个下拉菜单,我正在尝试选择值“cow_poop”。我目前正在这样做的方式是这样的。

    within('ant-select-selection') do
      find('cow_poop').click
    end
Run Code Online (Sandbox Code Playgroud)

这种方法的问题是它不起作用。

Poo*_*hav 5

.类名之前缺失,应该是 within('.ant-select-selection')

您还可以使用:

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

选择


find (:xpath, "//div[text()='cow_poop']").click
Run Code Online (Sandbox Code Playgroud)