decimal count = selenium.GetXpathCount("//div[@id='eventContent']");
This will return a div counter that has an id of eventContent - there is only one div , so you get a count of 1 (usually counts are int and not decimal s, by the way).
If you need div s counter use
int count = selenium.GetXpathCount("//div[@id='eventContent']/div");
This will count the number of eventContent of eventContent with id from eventContent . This should return 2 if required.
As for your GetText examples, I think GetText will return the text of the first node that selects the xpath argument. So,
selenium.GetText("//div[@id='eventContent'][1]")
you will get all the text of the parent div , which naturally contains all the children of div s, but with
selenium.GetText("//div[@id='eventContent'][1]/div")
you will get the text of only the first child div . This xpath selects all children of div s, but GetText only works with one element. If you want to examine the text of each child div in turn, you first need to get the count of the child div s, and then use the for loop to get each one in turn:
for(int i = 1; i <= count; ++i) { string childXpath = "//div[@id='eventContent']/div[" + i + "]"; string eventText = selenium.GetText(childXpath);
A for need a loop and manual xpath procedure (not a neater foreach ), since I believe that Selenium has no way to take xpath and return a set of elements.
source share