如何使用 Selenium 测试 jQuery TokenInput 字段
我无法使用 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
I'm unable to test a Tokeninput field in a form using selenium. The situation is when we type something, it gives a list to options to select but those options aren't part of the DOM. The text fills the field but doesn't select the item.
The code which I have written is:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于成功地完成了这项工作。要点如下: https://gist.github.com/1229684
该列表是 dom 的一部分(
div.token-input-dropdown
),它被添加为 body 元素的最后一个子元素,这可能就是您没有看到它的原因。如果您了解 tokeninput 插件正在做什么,您可以更好地了解您需要做什么。对于您创建的每个 tokeninput,插件:
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。之后,您只需在
div.token-input-dropdown li
上填写input#token-input-your_input_id
和“click
”即可与您正在寻找的选项相匹配。I finally succeeded in making this work. Here's the gist: https://gist.github.com/1229684
The list is part of the dom (
div.token-input-dropdown
), it's added as the last child of the body element, which is probably why you didn't see it.If you understand what the tokeninput plugin is doing, you can get a better idea of what you need to do. For each tokeninput you create, the plugin:
ul.token-input-list
(immediately beforeinput#your_input_id
)ul.token-input-list input#token-input-your_input_id
input#your_input_id
div.token-input-dropdown
So the most challenging part is finding the correct
ul.token-input-list
, because you have to find it based on its position relative to the original input, and the selenium webdriver doesn't let you navigate the dom.After that, you just fill in the
input#token-input-your_input_id
and "click
" on thediv.token-input-dropdown li
option that matches what you're looking for.