We run quite a bit of XPath queries & even though it is fairly fast
enough in Firefox, I think the way XPath expressions are "queried" in
Selenium can be improved. For example, in some of the pages, we "list"
the data in a specific table format: //table[@class='tblList'] would
get you all those specific tables on a single page. So if I wanted to
find some thing in the second table on that page, I'd try //table
[@class='tblList'][2] & so on.
Now, here is where you can optimize your queries. If I wanted to say
grab all the data in those tables & dump it out as a hash. Then I'd go
through each table cell & get the relevant data. But in doing so I
always end up using // query that means I always try to evaluate at
the root of the document. Instead it'd be faster if I can do something
similar as in the above Google groups discussion - i.e. I already know
my first table is //table[@class='tblList'][1]. So is there any way to
grab that node in selenium & "continue" my XPath using relative
syntax like ./tbody/tr[1]/td[1]/text(). Note the period at the
beginning of that query, which states that find the relevant text in
the table cell of the first table.
I couldn't find a way to do it but I believe this should speed up the
overall processing of queries, if you do a lot of XPath evaluation on
a given document.
E.g.
xpath=//table[@class='tblList'][1] would be CSS=table.tblList
XPath isn't native in Internet Explorer but CSS locators are so will
be a lot quicker
David Burns
http://www.theautomatedtester.co.uk/
On Jan 12, 7:50 pm, Aditya Ivaturi <ivat...@gmail.com> wrote:
> My query is based on this discussion here:http://groups.google.com/group/comp.lang.javascript/browse_thread/thr...
CSS locators are not as powerful as XPath. Obviously, I have omitted
some information in my original post. In this case for e.g., a single
page can have multiple tables of class 'tblList'. So in XPath, I can
say //table[@class='tblList'][1] to get me the first table that
matches my condition. But in case of CSS locators it is simply not
possible - at least using the CSS locators specification. The closest
you can come to is using some thing like table.tblList:nth-child(1),
but that will work if this table element is the first child of its
parent node. If you have any other element taking up the table's place
- that condition will fail. For e.g. if I have a couple of <br/>
elements before this particular table element, then this table is the
3rd child of its parent node.
Bottom line, I think XPath is a more programmer friendly & powerful
locator scheme. But the biggest hurdle is the stupid IE with its lame
JS engine and absolutely no support for XPath. Firefox had it since
1.0.
Regardless, I did find the answer to my original question & the answer
is no - there is no support for context nodes in Selenium since
Selenium never returns an element reference back to the client. It is
apparently possible in WebDriver though, but then I have to wait till
2.0 comes out.
So in XPath, I can
say //table[@class='tblList'][1] to get me the first table that
matches my condition. But in case of CSS locators it is simply not
possible - at least using the CSS locators specification. The closest
you can come to is using some thing like table.tblList:nth-child(1),
but that will work if this table element is the first child of its
parent node. If you have any other element taking up the table's place
- that condition will fail. For e.g. if I have a couple of <br/>
elements before this particular table element, then this table is the
3rd child of its parent node.
Bottom line, I think XPath is a more programmer friendly & powerful
locator scheme. But the biggest hurdle is the stupid IE with its lame
JS engine and absolutely no support for XPath. Firefox had it since
1.0.
I did look at that when I was experimenting with CSS selectors, but I
don't think you can use "filters" with nth-of-type. For e.g. in the
example I provided I cannot do table.tblList:nth-of-type(1). As far as
I know the only way to use it is table:nth-of-type(1). If I am missing
something, please do let us know.
I did look at that when I was experimenting with CSS selectors, but I
don't think you can use "filters" with nth-of-type. For e.g. in the
example I provided I cannot do table.tblList:nth-of-type(1). As far as
I know the only way to use it is table:nth-of-type(1). If I am missing
something, please do let us know.
I'm using Firefinder (an addon to firebug) to evaluate those CSS
queries & whenever I use filters with nth-of-type() it never returned
any resutls. So I tried it with CSSQuery (which is the javascript
library that Selenium uses) & the result was the same. May be I am
missing something? Can you try installing Firefinder in your FF
browser & see if you can use filters on the nth-of-type() & get
results back?
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.