经过Capybara的Dropbox?

发布于 2025-02-10 02:19:10 字数 1788 浏览 4 评论 0原文

我有一个下拉菜单。我希望Capybara通过它找到特定元素,然后单击它。我目前正在尝试在子句中执行一个,并在列表中迭代并找到此元素:“ 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>

因此在此HTML标签中。我有一个下拉菜单,我正在尝试选择值cow_poop。我目前这样做的方式就是这样。

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

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

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 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"> </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>

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带上头具痛哭 2025-02-17 02:19:10

在班级名称之前缺少
ins('。蚂蚁选择选项')

您也可以使用:

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

替代


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

. 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文