I am using WebDriver in Java.
I want to get all the amount values from the amount field below, so what I am planning to do it to loop throug each table row, and find if the check box is selected, set the amount to a number defined.

Example source code can be found here at: http://eric-lin.net/upload/index.php
I use the following Java method to find the amount field value:
public void fillInAllAmountForSelectedItems() {
List<WebElement> allItems = driver
.findElements(By
.xpath("//table[@id = 'bulkPaymentForm:itemTable']//tbody[@id = 'bulkPaymentForm:itemTable:tbody_element']//tr[contains(@class, 'handCursor row-border tranItemRow')]"));
System.out.println(allItems.size());
//return 3, expected
waitTimer(2, 1000);
for (WebElement item : allItems) {
System.out.println(item.findElement(By.xpath("//td[4]"))
.getAttribute("Value"));
}
}
Most of the time, the foreach loop will fail because of stale element exception. Which I don't understand because the DOM didn't change.
When it works, the foreach loop does not print anything so it looks like it doesn't locate the element correct.
How can I do to fix it, and what do I need to do to fulfill the purpose of this function to fill in amount value for all the checked items?
Thanks very much in advance.
wait()function? try to execute in step by step (debug mode) if you are using eclipseinputfield within thetdwill contain the amount, not thetditself.