Skip to Content
Personal Insights

How to find if an item is clickable or not?

Introduction

In this blog post, I wish to share the solution I used to determine if any page item’s hyperlink is active or not.

Main Content

I faced with this problem when I was building a bot which was expected to navigate through different pages of a web application using the “Next” button. This is a very normal way of designing navigation between pages using the “Previous” and “Next” buttons. These can be “buttons” OR they can be “simple text with hyperlink”. In my case, it was text with hyperlink.

 

The bot was expected to move through all the pages –> read the content on the page –> click on logout after last page content is read. My problem was how to identify if the bot has reached the last page? This was indicated by the “Next” hyperlink getting deactivated. To identify the real difference, do the following: –

Inspect the page source. To inspect, just right click on the page –> Choose Inspect Source. 

On the elements tab of the page inspection window that opens up, please find the appropriate HTML tag used for the element in question. For me, it looked like this: –

 

Please observe carefully, the “Previous” text’s hyperlink is inactive and “Next” text’s hyperlink is active. The HTML attribute “style” for “Previous” contains value “display: none;” and for the “Next” it just the text.

 

How do we get the HTML attributes at runtime ?

After searching through, I found a method “html” for the item which contains the entire string which is contained in the <>a</> in the above screenshot. This made it simple. The next problem was how to identify if the string contained these characters. To achieve, this I had to include the “String Utilities” library in the script section and use the function: ctx.string.existChar( ).

So, the final code transformed into the following: –

var html = ApplName.PageName.btNext.html();

if (ctx.string.existChar(html, 'display: none;') == e.error.OK) 
{
// Final page reached. Exit the step and proceed to click Logout
    ApplName.PageName.btLogout.click( );
    sc.endStep();
    return ;
}

 

Conclusion

Please check the HTML tags more in detail to get the right differentiating factor and use the html method to retrieve that information

 

Thanks ! 🙂

Be the first to leave a comment
You must be Logged on to comment or reply to a post.