Look for string on page, click adjacent Edit hyperlink

Although familiar with programming in general, I’m quite new to Kantu (and all I know of Selenium if from Kantu). It’s been an amazing journey for me using Kantu for automation. Here’s something that’s a bit complex for me but I think is very simple to implement. Would appreciate some tips and guidance.

There’s a table in the page that looks something like this (it can be 100 rows).

image

Here’s what I need: Given an Item ID, click on the Edit button. So if I’m given 356428, I want to automatically click the 2nd Edit button.

I’ll get the Item ID from the user via this trick Ask for user input with storeEval - UI.Vision RPA Software Forum | Discuss RPA Automation, Selenium IDE and OCR API Text Recognition, So I want to find ${!clipboard} and click the Edit in the same row.

I’ve played around with Kantu. Using the Select/Target, I have these information which might help in giving me the solution.

If I select 356428, I get
"Target": "//*[@id=\"clForm\"]/div[3]/div/table/tbody/tr[2]/td[1]",

To click the Edit button, it would be (same row, column 7)
"Target": "//*[@id=\"clForm\"]/div[3]/div/table/tbody/tr[2]/td[7]",

So the row number in tr[n] is the one I need to store in a variable (e.g. 170160 will be tr[3] and so on). Let’s say targetRow = n

Then I use the above variable to click the corresponding Edit button (not sure if this is right)
//*[@id="clForm"]/div[3]/div/table/tbody/tr[${targetRow}/td[7]/u

Alternatively, the Edit also has this JS (where it starts from 0. So 356428, the 2nd item is tr[2] or editTask(‘1’)

<td style="cursor:pointer;" onclick="javascript:editTask('1');" >

QUESTION: Is there a way that I search for “356428” and I get this as the result:
"Target": "//*[@id=\"clForm\"]/div[3]/div/table/tbody/tr[2]/td[1]",

If yes, how do I store the n from tr[n] into a variable so I can use it to target the Edit button.

Or do I have to use this method: Help in Dynamic table reading - #5 by rjndra - UI.Vision RPA - UI.Vision RPA Software Forum | Discuss RPA Automation, Selenium IDE and OCR API Text Recognition

Thanks

Here’s the portion of the HTML page that I need to search through:

<tbody style="height:200px;">
	<tr title=" Description: " class="InactiveEven">
		<td>&nbsp;126339
		</td>
		<td>&nbsp;CA
		</td>
		<td>&nbsp;Warehouse
		</td>
		<td>&nbsp;11/16/2018
		</td>
		<td>&nbsp;John Brown
		</td>
		<td>&nbsp;Some text here
		</td>
		<td style="cursor:pointer;" onclick="javascript:editTask('0');">&nbsp;
			<u>Edit</u>
		</td>
	</tr>

	<tr title=" Description: " class="InactiveEven">
		<td>&nbsp;356428
		</td>
		<td>&nbsp;WA
		</td>
		<td>&nbsp;Field Office
		</td>
		<td>&nbsp;06/20/2018
		</td>
		<td>&nbsp;Michael Smith
		</td>
		<td>&nbsp;Description here
		</td>
		<td style="cursor:pointer;" onclick="javascript:editTask('1');">&nbsp;
			<u>Edit</u>
		</td>
	</tr>

	<tr title=" Description: " class="inactiveOdd">
		<td>&nbsp;170160
		</td>
		<td>&nbsp;NY
		</td>
		<td>&nbsp;Branch
		</td>
		<td>&nbsp;12/20/2017
		</td>
		<td>&nbsp;Martin Wilson
		</td>
		<td>&nbsp;To be finished soon
		</td>
		<td style="cursor:pointer;" onclick="javascript:editTask('2');">&nbsp;
			<u>Edit</u>
		</td>
	</tr>

</tbody>`

Here is my solution:

  • Loop over the table, extract the text (in your case: number) of each row, until the right row is found. Then “number of loops” = “row number”.

  • Then use POS to click the x-th “Edit” button. <x> is the row number that we got from step 1.

Test macro for the 7-zip page. It finds the right download link (1st column), given the text in the 4th column. The only issue I see is that it might be a bit slow if your table has 100s of rows?

{
  "CreationDate": "2018-11-22",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://www.7-zip.org/download.html",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "7-Zip Source code",
      "Value": "wordtosearchfor"
    },
    {
      "Command": "store",
      "Target": "1",
      "Value": "myrow"
    },
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed"
    },
    {
      "Command": "label",
      "Target": "GetNextRow",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "${myrow} + 1",
      "Value": "myrow"
    },
    {
      "Command": "storeText",
      "Target": "/html/body/table/tbody/tr/td[2]/table[1]/tbody/tr[${myrow}]/td[4]",
      "Value": "t1"
    },
    {
      "Command": "echo",
      "Target": "t1=${t1}",
      "Value": ""
    },
    {
      "Command": "gotoIf",
      "Target": "\"${t1}\" != \"${wordtosearchfor}\"",
      "Value": "GetNextRow"
    },
    {
      "Command": "storeEval",
      "Target": "${myrow} - 1",
      "Value": "mylink"
    },
    {
      "Command": "echo",
      "Target": "Download link is in row ${myrow}, ${mylink}th link",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "link=Download@POS=${mylink}",
      "Value": ""
    }
  ]
}

Thanks Matt. I did something similar based on Help in Dynamic table reading - #5 by rjndra - UI.Vision RPA - UI.Vision RPA Software Forum | Discuss RPA Automation, Selenium IDE and OCR API Text Recognition which is similar to what you suggest. I’m currently testing it and will reach out to the community if I have any hiccups. Cheers!

Oh, I just reinvented the wheel :wink:

Here’s what I came up with. Thanks again!

{
  "CreationDate": "2018-11-22",
  "Commands": [
    {
      "Command": "store",
      "Target": "${!clipboard}",
      "Value": "myTaskSearch"
    },
    {
      "Command": "store",
      "Target": "0",
      "Value": "myRow"
    },
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed"
    },
    {
      "Command": "label",
      "Target": "myLoop_TaskSearch",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "${myRow}+1",
      "Value": "myRow"
    },
    {
      "Command": "storeText",
      "Target": "//*[@id=\"clForm\"]/div[3]/div/table/tbody/tr[${myRow}]/td[1]",
      "Value": "myTaskFound"
    },
    {
      "Command": "gotoIf",
      "Target": "\"${myTaskSearch}\"!=\"${myTaskFound}\"",
      "Value": "myLoop_TaskSearch"
    },
    {
      "Command": "clickAndWait",
      "Target": "//*[@id=\"clForm\"]/div[3]/div/table/tbody/tr[${myRow}]/td[7]",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "myRow=${myRow}",
      "Value": ""
    }
  ]
}

Let’s say Item ID is not unique and I want to add combination of Item ID + Statge.
How do we do that ? I’m struggling from few days!!!
Appreciate the help.