Testing for number of elements matching a given selector

10 views
Skip to first unread message

alex finn

unread,
Jan 11, 2011, 2:39:45 PM1/11/11
to pyccuracy
Hi guys,
I've just started playing around with pyccuracy recently and it looks
fantastic so far. However, I found couple of use cases when I do not
know how to test and I was not able to find explanation in the
documentation.
Specifically the use case I'm trying to test is a search results page
and I would like to validate that the page contains certain amount of
divs with a given class. It would also be nice to validate a content
of the first of these divs.
Unfortunately I was not able to come up with any solution working with
list of elements so I was wondering if I missed something obvious or
if there is a solution somebody else came up with.

Bernardo Heynemann

unread,
Jan 12, 2011, 7:01:59 AM1/12/11
to pycc...@googlegroups.com
Hey man!

Thanks for trying Pyccuracy, we hope you love it and help us evolve it.

The use case you specified would be solved using Pages. You can register the divs using Xpath (using indexes). I know it's not that practical, but if you find a better way of doing it, let us know and we may implement it.

Cheers,
Bernardo Heynemann


--
You received this message because you are subscribed to the Google Groups "pyccuracy" group.
To post to this group, send email to pycc...@googlegroups.com.
To unsubscribe from this group, send email to pyccuracy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyccuracy?hl=en.


alex finn

unread,
Jan 12, 2011, 7:41:23 AM1/12/11
to pyccuracy
hi Benardo,

could you please help me understand this a little bit more. If I
create a page like this:

from pyccuracy.page import Page

class SearchPage(Page):
url = '/'

def register(self):
self.quick_register("Search Results Entry",
"div.search_result")

How do I then validate that there are 10 entries matching this
selector? I would like to be able to do something like:

...
And I see 10 "Search Results Entry" div elements
And I see 1st "Search Results Entry" div contains "First search
result"
...

Now I'm trying to figure out how do I code an action that would count
number of entries. I do see a lot of methods in SeleniumBrowserDriver
that work with a single element but no methods that work with a
collection of elements. If you can point me to the browser driver or
selenium method that could be used to get a collection of elements
from the page matching a given selector and iterate over it - would be
fantastic.

Sorry if that is a lame question, it could be just a lack of Selenium
experience.

Bernardo Heynemann

unread,
Jan 12, 2011, 7:54:47 AM1/12/11
to pycc...@googlegroups.com
No question is a lame question.

I don't have it here to test it, but I'm pretty sure that there's a method called getXpathCount or something like that in SeleniumBrowserDriver.

If you create an action that uses that you should be fine!

If you have any more questions, just ask!

Cheers,
Bernardo Heynemann


--
Reply all
Reply to author
Forward
0 new messages