Monday, December 15, 2008

Select one of many similar elements by index in Selenium?

Imagine there are 10 web buttons on the page. All have the id button followed by a dynamic number. So the buttons would have id button12234, button12235,button12236 and so on. Now if you wish to select the second button from the top of the page.
Easy to this in QTP. Browser().Page().WebButton().Click("htmlid:=button.*","index:=1") should do the job.
In selenium use the following
xpath=(//input[contains(@id,'button')])[2]

The prefix xpath= is essential or this expression won't work.

1 Comment:

Shruti Ramalingam said...

Thanks for the great information in your blog Selenium Training in Chennai