简体   繁体   English

如何使用 Hound 从选择下拉列表中选择一个选项?

[英]How to select an option from a select drop-down list with Hound?

I have the following drop-down list:我有以下下拉列表:

<select id="cities" name="cities">
  <option value="paris">Paris</option>
  <option value="london">London</option>
  <option value="rome">Rome</option>
</select>

I am writing integration tests in Elixir with Hound and I'd like to select an element from the list above before submitting my form.我正在用HoundElixir 中编写集成测试,我想在提交表单之前从上面的列表中选择一个元素。 Can I do that with Hound?我可以用猎犬做到这一点吗?

I couldn't find anything about drop-down lists in the Hound documentation .我在Hound 文档中找不到有关下拉列表的任何信息。

Currently there is no Hound function dedicated to selecting an element from a drop-down list.目前没有专门用于从下拉列表中选择元素的 Hound 功能。

However, you can usefind_element/3 to find the element that corresponds to the option value you want to select, then feed this element to click/1 to select it:但是,您可以使用find_element/3找到与您要选择的选项值对应的元素,然后将此元素提供给click/1以选择它:

find_element(:css, "#cities option[value='london']") |> click()

More information on this GitHub issue有关此 GitHub 问题的更多信息


Implementation example实现示例

defmodule CustomHelpers.Hound do
  use Hound.Helpers

  def select_drop_down(drop_down_id, option) do
    find_element(:css, "##{drop_down_id} option[value='#{option}']") |> click()
  end

  def select_drop_down_within(element, drop_down, option) do
    find_within_element(element, :css, "##{drop_down_id} option[value='#{option}']") |> click()
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Ruby 进行自动化测试:从下拉列表中选择一个选项 - Automated test with Ruby: select an option from drop-down list 如何在不使用滚动和模拟用户活动的情况下从下拉列表中选择一个项目 - 在 TestCafe Studio 中拖动? - How select an item from the drop-down list without using scrolling and simulate user activity - Drag in TestCafe Studio? 如何使用 Selenium、Python 选择下拉菜单值 - How to select a drop-down menu value with Selenium, Python 下拉菜单在可见时不会选择该值 - Drop-down doesn't select the value when visible 如何在下拉量角器 e2e 测试中使用 select 选项 - How to select option in drop down protractorjs e2e tests 量角器在IE10中不会从下拉列表中选择 - Protractor Won't Select From Drop-Down in IE10 如何计算量角器中下拉选项的总数 - How to count total number of option of drop-down in protractor 如何在Telerik Test Studio中从下拉列表中选择项目 - how can select items from drop down list in telerik test studio 从下拉列表中更改登录用户以进行角色测试 - Changing logged in user from a drop-down list for role testing 无法 select 下拉列表在 testcafe - Unable to select drop down list in testcafe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM