Not able to select a checkbox using selenium
I have a readymade code and i'm trying to write tests for it using selenium. The code contains two or more than two checkboxes in following format with different ids like;
1. <input type="checkbox" id="8933059checkitem0"> 2. <input type="checkbox" id="8933059checkitem1"> ....
I'm using following xpath expression to grab the topmost checkbox :
Even placing '' after the above xpath expression is giving no results. I'm looking for a xpath expression using which i can grab the first checkbox only.
Thanks in advance
Try to enclose the expression before choosing the first item:
(//input[@type='checkbox'])[position()=1 and ancestor::div[@class='xyz']]
If you use  alone, in most cases it grabs all first children, not the very first child alone (as expected).
Actually, positional predicates are often misunderstood. They don't select items relative to their parents, they celect items within the sequence being processed.