Indexing over the results returned by selenium

Posted by Guy on Stack Overflow See other posts from Stack Overflow or by Guy
Published on 2009-12-17T14:40:06Z Indexed on 2010/04/18 10:33 UTC
Read the original article Hit count: 177

Filed under:
|
|

Hi

I try to index over results returned by an xpath. For example:

xpath = '//a[@id="someID"]'

can return a few results. I want to get a list of them. I thought that doing:

numOfResults = sel.get_xpath_count(xpath)
l = []
for i in range(1,numOfResults+1):
   l.append(sel.get_text('(%s)[%d]'%(xpath, i)))

would work because doing something similar with firefox's Xpath checker works:

(//a[@id='someID'])[2]

returns the 2nd result.

Ideas why the behavior would be different and how to do such a thing with selenium Thanks

© Stack Overflow or respective owner

Related posts about selenium

Related posts about xpath