I've been grappling with this issue for the majority of today; I'm trying to tally up the number of childNodes within a parent div. It's essentially mimicking a list where each childNode represents a row that I want to count. The HTML structure is as follows:
div<@class="list ">
div<@id="list-item-01">
div<@id="list-item-02">
div<@id="list-item-03">
div<@id="list-item-04">
div<@id="list-item-05">
...
</div>
I've mainly been attempting to utilize the getEval()
function in Selenium using some JavaScript.
Here are a couple of examples that have not worked:
String locator = "xpath=//div[contains(@class,'list')]";
String jscript = "var element = this.browserbot.findElement('"+locator+"');";
jscript += "element.childNodes.length;";
String locator = "xpath=//div[@class='list']";
String jscript = "var element = this.browserbot.findElement('"+locator+"');";
jscript += "element.childNodes.length;";
I am confident that the element exists and my xpath is accurate because when I tried using .isElementPresent
, it returned true. Therefore, there seems to be an issue with Selenium and divs.
I also experimented with using document.evaluate()
in my JavaScript command, but that approach was just as unsuccessful.