如何使用ui selectmenu(jQuery)和Selenium进行测试 [英] how to test using ui selectmenu (jQuery) and selenium

查看:97
本文介绍了如何使用ui selectmenu(jQuery)和Selenium进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用用于Firefox(版本3.6)的Selenium IDE插件记录"功能测试.我正在使用jQuery插件ui selectmenu(我认为其版本为1.8).我试图记录"下拉/选择组件中元素的选择.此下拉菜单是一个ui select增强组件.因此,实际的select元素是隐藏的,您最终将选择span元素和其他内容.这是硒记录的:

I'm trying to "record" a functional test using the selenium IDE plugin for Firefox (version 3.6). Im using the jQuery plugin ui selectmenu (I think its version 1.8). Im trying to "record" the selection of an element in a dropdown / select component. This dropdown is a ui select enhanced component. Therefore the actual select element is hidden and you end up selecting span elements and something else. This is what selenium records:

<tr>
   <td>click</td>
   <td>//a[@id='type-button']/span[2]</td>
   <td></td>
</tr>
<tr>
    <td>click</td>
    <td>ui-selectmenu-item-416</td>
    <td></td>
</tr>

问题在于,第二部分使用数字后缀,这是一种计数器(416).对于每个页面加载,此值都不同,因此我看不到如何使它自动化!?

The problem is that the second part uses a number suffix, a kind of counter (416). This value is different for every page load, and therefore I don't see how I can automate it!?

如何获得可预测的结果并进行测试?或者还有其他方法可以实现?

How can I get a predictable result and test this?, or is there some other way to do it?

谢谢!

推荐答案

使用Selenium自动化jQuery selectmenu小部件很痛苦.一个简单的唱片播放几乎是行不通的.尝试执行以下步骤来自动进行选择-

The jQuery selectmenu widget is painful to automate with Selenium. A simple record-playback will hardly ever work. Try the following steps to automate the selection -

  1. 键入您需要选择的项目.

  1. Type in the item you need to select.

按Backspace键,以便selectBox可以搜索"该项目.

Hit Backspace so the selectBox can "search" for the item.

为搜索到的项目模拟向下箭头键.

Simulate the down arrow key for the searched item.

从下拉列表中选择第一项.

Select the first item from the dropdown list.

这是这些步骤的源代码(在Java中).您应该能够使它们适应IDE.

Here is the source code (in Java) for these steps. You should be able to adapt these to the IDE.

selenium.type("selectMenu_descriptor", "item_to_be_selected");
selenium.typeKeys("selectMenu_descriptor", "\b"); 
selenium.keyDown("selectMenu_descriptor", "\\40");
selenium.click("css=a.ui-corner-all[tabindex=\"-1\"]");

这篇关于如何使用ui selectmenu(jQuery)和Selenium进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆