[英]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.我正在用Hound在Elixir 中编写集成测试,我想在提交表单之前从上面的列表中选择一个元素。 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 问题的更多信息
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.