QA Graphic

Selector using JQuery

Click on an anchor tag using jquery content selector

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

<script>
$( "a:contains('Sign up')" ).click();
</script>

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

<script>
$( "a:contains('Sign up')" ).eq(0).click();
</script>

 

About

jQuery is the most popular Javascript library on the Internet. Chances are that websites that your testing use it. These posts are all about tips and tricks for QA testing.

Schedule

FridayMacintosh
SaturdayInternet Tools
SundayOpen Topic
MondayMedia Monday
TuesdayQA
WednesdayAffinity
ThursdayBBEdit