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 :

"/html//div[@class='xyz']//input[@type='checkbox']"

Even placing '[1]' 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

Answers


Try to enclose the expression before choosing the first item:

(/html//div[@class='xyz']//input[@type='checkbox'])[1]

or

(//input[@type='checkbox'])[position()=1 and ancestor::div[@class='xyz']]

If you use [1] 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.


Need Your Help

Django and Haystack search issue

python django-haystack

I am running Python 2.6, the lastest haystack, django 1.2 beta and I have tried both Woosh and Xapian backends.

Create a folder in C# project dynamically

c# .net winforms

I have to create a folder in C# project dynamically and add files to it.