右键单击时,会出现上下文菜单并提供一些 selenium 命令。它不提供所有 selenium 命令。命令列表是动态的,并且会使用最常用的 selenium 命令进行更新。我想让上下文菜单的命令列表静态。知道我该怎么做吗?
user306792
问问题
4967 次
1 回答
2
扩展 Selenium IDE以将您自己的自定义命令添加到右键单击上下文菜单很容易。
具体来说,您需要编写一些 Javascript 来将您需要的额外命令添加到 CommandBuilders。
添加命令生成器。命令生成器通过在右键单击元素时在上下文菜单中显示可用命令来帮助用户将命令添加到测试中。
Selenium 扩展页面上有许多示例,例如,这个示例很好地演示了如何使与 HTML 选择元素相关的命令出现在菜单中:
CommandBuilders.add('accessor', function(window) {
// Define the command that we will return
var result = { accessor: "selectedLabel", disabled: true };
// Determine if the user has clicked on a select tag
var element = this.getRecorder(window).clickedElement;
if (element && element.tagName && 'select' == element.tagName.toLowerCase()) {
// The target is the select element
result.target = this.getRecorder(window).clickedElementLocators;
result.disabled = false;
var selectedIndex = element.selectedIndex;
if (selectedIndex == -1) {
// Handle no selection as the empty string
result.value = '';
}
else {
// Capture the inner HTML (the text shown in the select) as the value to be matched
var selectedOption = element.options[selectedIndex];
result.value = exactMatchPattern(selectedOption.innerHTML);
}
}
return result;
});
创建扩展后,您可以轻松地在 Selenium IDE 中的 Options->Options 下手动加载它们,或者将它们捆绑为 Firefox 插件的一部分(这里有一个很好的教程)
于 2010-11-12T21:48:33.987 回答