6

For a Drupal site, I have written a test script in Selenium IDE that logs in as the administrator, adds a new user and peforms a series of tests on the registration page.

Once this user has been added, I would like to add to this script so that it then goes to the user panel, and removes it again. Getting to the user admin page is simple, and I have the username field stored from earlier, say "test user 2".

In the user admin panel, we have this:

Drupal user admin panel

What I need to do is find a way to select the checkbox next to the appropriate user. The problem is that the checkbox is marked up as such:

<input type="checkbox" class="form-checkbox" value="4" id="edit-accounts-4" name="accounts[4]">

Now, as mentioned before, the only information I have about the user is the username. Unfortunately the id of the checkbox references the internal user id, which is 4. That's information I don't have. However, the username link I can locate because I have the value stored. I can just locate any anchor element containing the username string "test user 2". Markup is:

<a title="View user profile." href="/user/4">test user 2</a>

Since I have "test user 2" as the username already stored, I can select this element in my test case. But what I want to do is select the checkbox next to it. There's two ways that I think this can be done:

1) Extract the number "4" from the href attribute and use that to select the checkbox, since all checkbox ids will be of the form "edit-accounts-x" where x is a number.

2) Use some funky xpath to determine that the checkbox is on the same row as the username I have stored.

Thoughts?

1 Answer 1

4

Use an xpath like so:

//table[@id='<tableID>']/descendant::tr[td[.='test user 2']]/td[1]/input

this assumes that you are trying to click on the checkbox for "test user 2" and that it is in the first column.

The descendant is used because some browsers put in a element if it is not specified and some dont.

This way is much less intensive than getting the id, stripping out the bits you don't want, getting another part of an id and adding bits into it. If the id's of the checkboxes change (which drupal can do now and again if the devs are not on the ball from personal experience) you don't have to rewrite the the code that pulls out part of an id and inserts it into another id.

Edit

Also since you are using Selenium IDE you don't have as much functionality available to you by default as you would with a programming language (think Selenium RC/Selenium 2) which will probably make option 1 even more of a ball ache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.