How to convert XPath to CSS selector

3,905 views
Skip to first unread message

Ann Millikin

unread,
May 6, 2013, 12:01:28 PM5/6/13
to fire...@googlegroups.com
I love using Firebug and Firepath to determine XPath selectors for my automated scripts to test Web sites.  However, sometimes it would be better for me to select Web elements via CSS rather than XPath.  Maybe I'm missing something, but when I click the arrow in Firebug and then click on an Web Element, the XPath is listed as follows:

.//*[@id='main']/div/div[2]/table[1]/tbody[2]/tr[2]/td[2]
  

When I change XPath to CSS and click on the arrow and then the web element, supposed the equivalent CSS selector appears as follows:

.guidance

However, this isn't specific enough so rather than selecting the one cell, it selects the entire column.  I want to grab row 2 of tbody 2.  Not being that familiar with CSS, I am not sure how to narrow my results.  Is there a way to get FirePath to be more specific?

Thank you!
Ann
XPath selector.pdf
Css selector.pdf

Pierre Tholence

unread,
May 8, 2013, 7:46:43 AM5/8/13
to fire...@googlegroups.com
Hi Ann,

There is currently no way to get FirePath to be more specific when it
comes to CSS selector.
This explains how you could narrow your result:
http://stackoverflow.com/questions/15731332/how-to-convert-xpath-to-css

So I think the CSS selector equivalent to the XPath you provided is:
#main > div > div:nth-of-type(2) > table:nth-of-type(1) >
tbody:nth-of-type(2) > tr:nth-of-type(2) > td:nth-of-type(2)

Regards,
Pierre
> --
> You received this message because you are subscribed to the Google Groups
> "FirePath" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to firepath+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages