How to count the number of profiles on a web page and print a message depending on the number

To simulate this scenario, we will use the Profiles table on Reference Application and below steps will walk us through the process:

1- Define locators for steps that log into an existing user

2- Define a locator for a step that navigates to Profiles page

3- Define a locator for a step that clicks on Table View link as below:

 Main page:mceclip0.png

In Profiles page:

mceclip1.png

Steps layout:

mceclip0.png

4- Now it’s time to count the number of profiles on the table. To do that, we can use the ‘count’ function with the ID table header. When inspecting the ID for the first profile, we see that the header has a unique scope which is “row”.  We can use that as an XPath as below:

//th[@scope='row']

To further enhance the XPath, we can use an additional attribute which is 'class'. The XPath will be:

//th[@scope='row' and @class='ng-binding']

Now we wrap the XPath with parentheses and use 'count' function at the beginning of the XPath as below:

count(//th[@scope='row' and @class='ng-binding'])

Depending on the number of profiles on the page, we should get the total number.

mceclip4.png

5- Next, we define a locator using the XPath above, use it in a step with Get_Web_Value command and select 'Number' or 'String' as Type. However, if 'Number' is used, it will provide decimal zeroes to the number, so we can use regular expression ‘\..*’ in the Characters to Exclude section to exclude the dots and anything after them.

6- Next, we can use IF statements to direct our steps to print a message according to the number stored in the variable in Get_Web_Value step.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Please sign in to leave a comment.