开发者

Selenium Automation

开发者 https://www.devze.com 2022-12-13 08:06 出处:网络
Is there any way in Selenium ide, so that we get list and handlers for all controls provided on any page?

Is there any way in Selenium ide, so that we get list and handlers for all controls provided on any page? So if we get that we can test that one by o开发者_如何学编程ne using RC and it'll greatly helpful when there are more then 40 controls on page. In that case, it'll become very tiresome to record for all.


In Selenium you can use getXpathCount to get the number of matching elements and then loop through them. The following Java example will output the IDs of the checkboxes on the page:

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"));
}

In the WebDriver API (to be merged into Selenium 2) there is a findElements method that returns a list of matching elements. The above example would look something like:

for (WebElement checkbox : driver.findElements(By.xpath("//input[@checkbox]"))) {
    System.out.println(checkbox.getAttribute("id"));
}


It could be possible to do with getEval and a Javascript routine to examine the DOM. There's an example here for looking for the id's of checkboxes on a page: http://seleniumhq.org/docs/05_selenium_rc.html#executing-javascript-from-your-test

0

精彩评论

暂无评论...
验证码 换一张
取 消