Selenium get dynamic ID XPath -
i'm new on selenium, new here , english not best.
i'm using selenium .net ...
i have html page number of events different:
<div id="eventcontent" style="text-align: center;"> <div class="event" id="event-8971062"> <ul> <li ...></li> <li ...></li> <li ...></li> </ul> </div> <div class="event odd" id="event-9224880"> <ul> <li ...></li> <li ...></li> <li ...></li> </ul> </div> </div>
i need check datas in different divs count dynamic , (event)id dynamic too. i'm trying find out count of divs @ first does'nt work. try this:
defaultselenium selenium = new defaultselenium(...); decimal count = selenium.getxpathcount("//div[@id='eventcontent']");
but brings 1 result , not 2 example.
when try:
console.writeline(selenium.gettext("//div[@id='eventcontent'][1]"));
it prints divs, when do:
console.writeline(selenium.gettext("//div[@id='eventcontent'][1]/div"));
it prints first div , not understand why. kind , give me explaination of whats going on here , i'm wrong?
thanks in advance elur
decimal count = selenium.getxpathcount("//div[@id='eventcontent']");
this return count of div
s have id
of eventcontent
- there 1 div
this, why count of 1 (count variables typically int
s rather decimal
s, incidentally).
if want count of contained div
s, use
int count = selenium.getxpathcount("//div[@id='eventcontent']/div");
this count number of div
children of div
id
of eventcontent
. should return 2, desired.
as gettext
examples, think gettext
return text of first node xpath argument selects. with
selenium.gettext("//div[@id='eventcontent'][1]")
you entire text of parent div
, naturally contains child div
s, with
selenium.gettext("//div[@id='eventcontent'][1]/div")
you text of first child div
. xpath selects child div
s, gettext
operates on single element only, believe. if want examine text of each child div
in turn, you'll need first count of child div
s, use for
loop each 1 in turn:
for(int = 1; <= count; ++i) { string childxpath = "//div[@id='eventcontent']/div[" + + "]"; string eventtext = selenium.gettext(childxpath); // processing of eventtext }
a for
loop , manual xpath processing needed here (rather neater foreach
), believe selenium doesn't have way of taking xpath , returning collection of elements.
Comments
Post a Comment