Selenium ide 中有什么方法可以让我们获得任何页面上提供的所有控件的列表和处理程序吗?因此,如果我们得到了这一点,我们可以使用 RC 进行一一测试,当页面上有超过 40 个控件时,这将非常有帮助。在那种情况下,为所有人录制会变得非常烦人。
问问题
1642 次
2 回答
2
在 Selenium 中,您可以使用它getXpathCount
来获取匹配元素的数量,然后遍历它们。以下 Java 示例将输出页面上复选框的 ID:
int checkboxCount = selenium.getXpathCount("//input[@type='checkbox']").intValue();
for (int i = 1; i < checkboxCount + 1; i++) {
System.out.println(selenium.getAttribute("//body/descendant::input[@type='checkbox'][" + i + "]@id"));
}
在 WebDriver API(要合并到 Selenium 2 中)中有一个findElements
方法可以返回匹配元素的列表。上面的例子看起来像:
for (WebElement checkbox : driver.findElements(By.xpath("//input[@checkbox]"))) {
System.out.println(checkbox.getAttribute("id"));
}
于 2009-12-08T12:25:40.673 回答
0
可以使用 getEval 和 Javascript 例程来检查 DOM。这里有一个示例用于在页面上查找复选框的 id:http: //seleniumhq.org/docs/05_selenium_rc.html#executing-javascript-from-your-test
于 2011-04-11T13:20:58.523 回答