English 中文(简体)
Selenium Automation
原标题:

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 one 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





相关问题
Javascript communication with Selenium (RC)

My Application has a lot of calculation being done in JavaScript according to how and when the user acts on the application. The project prints out valuable information (through console calls) as to ...

Running automated Web browser tests under Hudson

I m running Hudson for my automated builds and love it. I d now like to create automated Web browser tests using either WaTiN (preferred) or Selenium. As my Hudson runs as a Windows service (under ...

Using a Java library with Scala reserved words

I m using an external library written in Java (Selenium). One of the function calls has the signature type(String, String), and I keep getting compiler errors when trying to call it from Scala, that ...

Heightened privilege selenium browsers on Windows 7 (x64)

I make use of *firefox and *iexplore etc. within my selenium tests to get around the issue of self-signed SSL certificates on my local machine. Unfortunately, now that I ve moved from XP over to 7, ...

Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Selenium IDE: Incrementing values by 1 and 71

Currently I m incrementing a value called wert by 1 with the following code: getEval storedVars[ wert ]=${wert}+1; The value wert is something like 80401299. I want to add 1 to the value, if it ...

热门标签