如何使用 Selenium 测试 jQuery TokenInput 字段

发布于 2024-11-26 16:38:47 字数 671 浏览 3 评论 0原文

我无法使用 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 技术交流群。

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

发布评论

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

评论(1

╰ゝ天使的微笑 2024-12-03 16:38:47

我终于成功地完成了这项工作。要点如下: https://gist.github.com/1229684

该列表是 dom 的一部分( div.token-input-dropdown),它被添加为 body 元素的最后一个子元素,这可能就是您没有看到它的原因。

如果您了解 tokeninput 插件正在做什么,您可以更好地了解您需要做什么。对于您创建的每个 tokeninput,插件:

  1. 创建一个 ul.token-input-list (紧接在 input#your_input_id 之前)
  2. 创建一个 ul.token-input- list input#token-input-your_input_id
  3. 隐藏 input#your_input_id
  4. 创建一个 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:

  1. creates a ul.token-input-list (immediately before input#your_input_id)
  2. creates a ul.token-input-list input#token-input-your_input_id
  3. hides the input#your_input_id
  4. creates a 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 the div.token-input-dropdown li option that matches what you're looking for.

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