我无法使用 selenium 测试表单中的 Tokeninput 字段。情况是当我们输入一些东西时,它会给出一个可供选择的选项列表,但这些选项不是 DOM 的一部分。文本填充字段但未选择项目。
我写的代码是:
Given admin user is on schedule interview page
And he select "obie[1]" and "DHH[1]" from the candidate name(s) auto sugget field
**step defination**
Given /^he select "([^"]*)" and "([^"]*)" from the candidate name\(s\) auto sugget field$/ do |arg1, arg2|
within(:css, "#interview_template_candidate_names_input") do
fill_in('tmp',:with => arg1) --tmp is name of the token input field
find("li:contains('obie[1])'").click
save_and_open_page
end
end
最佳答案
我终于成功地完成了这项工作。这是要点:https://gist.github.com/1229684
列表是 dom ( div.token-input-dropdown
) 的一部分,它被添加为 body 元素的最后一个子元素,这可能就是您没有看到它的原因。
如果您了解 tokeninput 插件的作用,就可以更好地了解您需要做什么。对于您创建的每个 token 输入,插件:
- 创建一个
ul.token-input-list
(紧接在input#your_input_id
之前) - 创建一个
ul.token-input-list input#token-input-your_input_id
- 隐藏
input#your_input_id
- 创建一个
div.token-input-dropdown
所以最具挑战性的部分是找到正确的 ul.token-input-list
,因为您必须根据它相对于原始输入的位置找到它,而 selenium webdriver 不允许您导航 dom。
之后,您只需填写 input#token-input-your_input_id
和 click
上的“div.token-input-dropdown li
”与您要查找的内容匹配的选项。
关于ruby-on-rails - 如何使用 Selenium 测试 jQuery TokenInput 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6842464/