April 22, 2019

Selector using JQuery

jQuery selector functionality is pretty powerful. You can select All, IDs, Names, etc. It's a good way to perform an action. There's a trick to use when you don't have an ID and the page content tree changes. You can use the jQuery Contains() selector.

This is useful when you want to click on a specific Anchor tag and using an XPath isn't going to help since the content may change. (Thus frequently failing automation runs)

Simple Example

$( "a:contains('Sign up')" ).click();

The only problem with the above is if you have multiple anchor tags with the same text. Simply add the following reference:

$( "a:contains('Sign up')" ).eq(0).click();


Add your Comments

Feel free to leave a comment about this post.

- Feel Free to add HTML to your comment!