loadrunnertruclient

Click on a link beside text in TruClient


We have a page where with dozens of rows listing cases that we have created. We have named the cases unique so we can use a loop in TruClient to scroll down the page until we find that text. Our page has us then clicking on the link to the left of that text. It's very straight forward in the HTTP protocol as we can use regex to easily pull out the link but with TruClient we can't see that.

The latest link is not always at the top or bottom of the screen, and we can't grab the link details before we get to this page (functionality has us creating this case, and the case ID isn't presented to the page before this)

The closest functionality that I can see would be use a Click on link took, and use the "Related Object" and point it to the text that we want to identify, but there isn't a way to parameterise the text that we want to use as the anchor.

So in the example below the latest case that I created was Name20200323005 and I want to click on the Link to the right of it.

Has anyone done anything like this before, or suggest anything we could research?

mock up of screen


Solution

  • First I want to make sure I understand your request clearly. The task is let TruClient click the link based on search the value of Name###########. Is it right?

    TruClient support several ways to identify the test object:

    1. Automatic
    2. Descriptor
    3. JavaScript
    4. XPath

    I don't think the automatic or descriptor are fit for this request. We need to write some JS code complete the request.

    1. Change the object identification method to js from a Step > Object > ID Method.
    2. Click the edit icon from the right of the input box. Make sure the evaluated value of the JS code is reference to the right DOM object. Here is a sample code base on your example to filter the Link element:

    Added reference firstChild as you mentioned the link is contained in a div element. Glad to know it works. :)

    Array.prototype.slice.call(document.querySelectorAll('td'), 0).filter(td=>td.innerText=="Name20200323005")[0].previousElementSibling .previousElementSibling.firstChild