# Selenium - using jquery locators instead of xpath

**URL:** <https://www.ruby-forum.com/t/selenium-using-jquery-locators-instead-of-xpath/167977>\
**Category:** Rails\
**Created:** [May 14, 2009, 4:13pm UTC](https://www.ruby-forum.com/t/selenium-using-jquery-locators-instead-of-xpath/167977 "2009-05-14T16:13:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [May 14, 2009, 4:13pm UTC](https://www.ruby-forum.com/t/selenium-using-jquery-locators-instead-of-xpath/167977/1 "2009-05-14T16:13:21Z")

</div>

I’m writing some selenium tests and find myself doing stuff like this a  
lot:

@browser.click("//div[@id=‘four-col-bd’]//div[contains(@class,  
‘column’)]//a")

In this case i want to click on the first link in the first column in a  
div that has a group of four columns in it.

I’m thinking it would be nicer to use jquery-style dom element selectors  
for this sort of thing…can anyone think of a way i could lever it in  
there?

BTW, in case anyone’s wondering, i have been using the selenium ide to  
generate test scripts but i find that the link locators tend to be too  
data-specific: that is, the ide records that you clicked on a link by  
saying “link=\<link\_html\>”, where link\_html is the visible text in the  
link. This seems too fragile and data-dependent, that’s why i’m trying  
to generalise it a bit to use the page structure instead.
