How to select a column(<td></td>) and click a link(<a href="#">link</a>) of a row(<td></td>) in table of webpage

uiautomation
studio

#1

I already read the following article to learn the usage of “UiPath.Core.FindChildren” activity,

but I could not solve my problem yet, so I hope you to help me to solve my problem.

what I want to know is how to select td tag in every row of the following table,
and my last goal is to click a link in the second td tag in every row of the table.

<table>
<tr>
  <th >aaa</th>
  <th>bbb</th>
  <th>ccc</th>
  <th>ddd</th>
  <th>eee</th>
  <th>...</th>
  ....
</tr>
<tr>
  <td class="NUMBER">1</td>
  <td class="PROJECT_NAME"><A onclick=javascript:display(0,1,0) href="#">title1</A></td>
  <td class="BID_METHOD"> </td>
  <td class="DOCUMENT_LIST"><a onclick=javascript:display2(0,3,0) href="#"><img src="button.gif" /></a></td>
  <td class="classname4"> </td>
  <td class="classname5">...</td>
  ....
</tr>
<tr>
  <td class="NUMBER">2</td>
  <td class="PROJECT_NAME"><A onclick=javascript:display(0,1,0) href="#">title1</A></td>
  <td class="BID_METHOD"> </td>
  <td class="DOCUMENT_LIST"><a onclick=javascript:display2(0,3,0) href="#"><img src="button.gif" /></a></td>
  <td class="classname4"> </td>
  <td class="classname5">...</td>
  ....
</tr>
<tr>
  <td class="NUMBER">3</td>
  <td class="PROJECT_NAME"><A onclick=javascript:display(0,1,0) href="#">title1</A></td>
  <td class="BID_METHOD"> </td>
  <td class="DOCUMENT_LIST"> </td>
  <td class="classname4"> </td>
  <td class="classname5">...</td>
  ....
</tr>
<tr>
  <td class="NUMBER">4</td>
  <td class="PROJECT_NAME"><A onclick=javascript:display(0,1,0) href="#">title1</A></td>
  <td class="BID_METHOD"> </td>
  <td class="DOCUMENT_LIST"><a onclick=javascript:display2(0,3,0) href="#"><img src="button.gif" /></a></td>
  <td class="classname4"> </td>
  <td class="classname5">...</td>
  ....
</tr>
  ....
</table>

I use “UiPath.Core.FindChildren” activity to get rows of a table in a webpage as
a variable “ReturnedChildren” - Variable type: IEnumerable.

The properities is following…

"UiPath.Core.FindChildren"
Input

  • Filter:

“<webctrl tag=‘TR’ />”

Target

  • selecter:

“<html htmlwindowname=‘AccepterGoodsMenu2’ title=’{WEBPAGE_TITLE}’ />
<webctrl aaname=‘WEBTABLENAME*’ tag=‘TABLE’ />”

Output

  • Children:

ReturnedChildren

And use “UiPath.Core.Activities.ForEach<UiPath.Core.UiElement>” like this.

Foreach row in ReturnedChildren
 Highlight Element: row

It runs fine that “Highlight” activity highlight every row(<tr></tr>) in the table.

And what I really want to know is how to select <td>'s in every row of the table.
My final goal is to click a link in the second “td” in every row of the table.

Foreach row in ReturnedChildren
 Foreach td in row
    System.Activities.Statements.WriteLine
      Text: row.????????????????             <- "How can I write here?"

Hope this community help me, and whom is having same problem as me.
Thank you in advance.


How to select First row(contains link) in a table and click on that link from a web page
#2

Try changing below

  1. find_descendents instead of find_children

  2. filter tag to TD instead of TR( or A if you have to click link)

  3. pass your “row” to a click activity -> element property


#3

@vvaidya Thank you for your reply.
I would like to try “find_descendents” activity later.

I’ll report the result just after I try.

Thank you :slight_smile:


#4

It’s not an activity, it’s one of the option in scope property of find children activity.

Thanks,
Vinay


#5

@vvaidya Thank you for your kindly advice.
Just after I replied you, I found “FIND_DESCENDANTS” option in “find children” activity.


#6

I followed @vvaidya’s answer, and that code ran successfully.
Thank you @vvaidya.

But I would like to select every tr, and then, select td in a tr.
What I want to do exactly is like the following code,

FindChildren
-Input
--Filter :<webctrl tag='TD' classname='CLASSNAME1' />
--Selector :<html htmlwindowname='AccepterGoodsMenu2' title='TITLENAME' />
<webctrl tag='TABLE' />
-Option
--Scope
---FIND_DESCENDANTS

foreach tr in table
  foreach td in tr
    select the second td tag, 
      and copy a link text, 
      and click a link, 
      (then opens new popup window),
      copy the table in the new popup window, and save it as csv file
      close the new popup window
    select the 4th td tag, 
       and click a link,
      (then opens new popup window),
       download pdf file
      close the new popup window

So I have to do another things in every row of the table.
(I updated html web table code what I posted before)

I searched this forum and found the following replies
that two expression for browser and selector won’t exist.


So foreach-foreach code can not be run, is my understanding correct?
And if no, How should I traverse “td <- tr <- table”.

Thank you,


#7

I guess you could use the same TD filter and just pick the Even elements in For Each loop.

children.Where(Function(child, index) index Mod 2 <> 0)

Addition : The above formula is for Odd numbers, but since the Index starts from zero , your Even number element will have Odd number Index.

you don’t have to copy the text

child.Get("aaname").ToString - add this to Set To Clipboard Activity


#8

you don’t have to copy the text
child.Get(“aaname”).ToString - add this to Set To Clipboard Activity

@vvaidya I appreciate your kindly help, and I needed to explain
what I really want to do in details, but I didn’t do so enough,
I want to copy the link text to name a file as the link text name, seriously.

Thanks to @vvaidya, I can parse link text in every rows,
and finally, I click a link text in td of a row!!! wow!

I summed up what I’ve done the following…

FindChildren
-Input: “”<webctrl tag=‘TD’ classname=‘PROJECT_NAME’ />"
-Selector:<html htmlwindowname=‘HTMLWINDOWNAME2’ title=‘TITLENAME’ />
<webctrl aaname=’*’ css-selector=‘body>table>tbody>table’ tag=‘TABLE’ />
-Options
–FIND_DESCENDANTS
-Output
–Children: ReturnedChildren

ForEach<UiPath.Core.UiElement>
-Misc
–TypeArgument:UiPath.Core.UiElement
–Values:ReturnedChildren

System.Activities.Statements.Assign
-Misc
–To: linkname
–Value: row.Get(“aaname”).ToString

SetFocus
-Target
–Element: row

UiPath.Core.Activities.Click
-Target
–Element:row
–CloppingReegion:(25,25,0,0)

Variables
-koji
–Variable type: String
–Scope: Sequence

I think the use of Click activity “CloppingReegion:(25,25,0,0)” is
a little bit of rough operation.

Are anyone advise me if there is a better way to click the a link text
without setting “Target -> CloppingReegion:(25,25,0,0)”?

Thank you,


#9

If this is to click on link inside TD, then pass below into Element for Click Activity instead of row

row.FindFirst(FindScope.FIND_DESCENDANTS,new Selector("<webctrl tag='A' />"))

This will get the First Element with Tag A inside the specific TD child.

Before that,

Try changing your Filter tag to “<webctrl tag=‘A’ />” instead of “<webctrl tag=‘TD’ />” and see if your code still works.

A will get all the links inside TD,


#10

@vvaidya, It completely works!
Your advice is better and smarter than my setting “CloppingReegion:(25,25,0,0)”,
and it works without changing Filter tag to “” instead of “”.
but there is no doubt because I set DataTable “ReturnedChildren” to loop-ForEach.

FindChildren
-Input: “”"

@vvaidya, how do you code if you want to click <td><a href="#" onclick=“javascript:display(0,1,0)”>the second link</a></td> and <td><a href="#" onclick=“javascript:display2(0,1,0)”>the 4th link</a></td> in a “<tr></tr>” in a single ForEach sequence, or ForEach-ForEach sequence? Is it possible or not, if not, what is the better way to make?

I can’t express my appriciation anymore,
Huge thank you @vvaidya :slight_smile:


#11

As I said earlier…

Find Children
Find_Descendants scope
<webctrl tag=‘A’ /> as filter should work. in single foreach


#12

@vvaidya, ok I tried your way, and found that you are really awesome.
Thank you @vvaidya.


#13

I am afraid that my trial fails in my actual scene.

UiPath.Core.Activities.FindChildren
-Input
–Filter:"<webctrl tag=‘TD’ classname=‘DOCUMENT_LIST’ />"
-Target
–Selector:"<html htmlwindowname=‘AccepterGoodsMenu2’ title=‘CALS/EC’ />
<webctrl tag=‘TABLE’ />
"
-Options
–Scope: FIND_DESCENDANTS

UiPath.Core.Activities.ForEach<UiPath.Core.UiElement>
-Misc
–TypeArgument: UiPath.Core.UiElement
–Values: ReturnedChildren

UiPath.Core.Activities.Click
-Target
–Element:row.FindFirst(FindScope.FIND_DESCENDANTS,new Selector("<webctrl tag=‘A’ />"))

Because every <td class=“DOCUMENT_LIST”>…</td> does not always have a href link,
so if there is not a href link in td clause, Click Activity fails.

I tried UiPath.Core.Activities.UiElementExits to check if a href link exists or not,
and then pass If-Else Activity. But it fails

UiPath.Core.Activities.UiElementExits
-Target
–Element: row.FindFirst(FindScope.FIND_DESCENDANTS,new Selector("<webctrl tag=‘A’ />"))

Element Exists : Cannot find the UI element corresponding to this selector: <webctrl tag='A' />

Could you tell me how to skip ForEach if a href link does not exist?

Or In FindChildren Activity, are there any way to set “Input-Filter” property to define that
tag=‘TD’ and (TD tag has classname=‘aaa’, or classname=‘bbb’)?

I am very close to my goal, but I’m not yet.
Hope my efforts also contribute this community, thank you,


#14

This should work. Straight forward.

I don’t think you need to worry about TD & TR,if you have to click only the Links.

UiPath.Core.Activities.FindChildren
-Input
–Filter:"<webctrl tag=‘A’ />"
-Target
-Selector - <html htmlwindowname=‘AccepterGoodsMenu2’ title=‘CALS/EC’ /> <webctrl tag=‘TABLE’ />
-Options
–Scope: FIND_DESCENDANTS

UiPath.Core.Activities.ForEach<UiPath.Core.UiElement>
-Misc
–TypeArgument: UiPath.Core.UiElement
–Values: ReturnedChildren

UiPath.Core.Activities.Click
-Target
Element:row


#15

@vvaidya , yeah, your advice actually worked, and your code tracks all A href links.
But FindChildren with Filer “<webctrl tag=‘A’ />” select all A tag links,
so it clicks all links including what is NOT needed to be clicked.


#16

In every row, there are two “A tag” links what I want to click,

-First

      <TD class="PROJECT_NAME">
        <A href="#" onClick="javascript:display(0,1,0)">title1</A>
      </TD>

-Second

      <TD class="DOCUMENT_LIST">
             <A href="javascript:display2(0,16,0)">
               <IMG src="buttonDisplay.gif" border="0" alt="Show"></A>
      </TD>

and then I planned,
first, let’s click “<TD class=“PROJECT_NAME”><A href=”#" onClick=“javascript:display(0,1,0)”>title1</A></TD>",
second, let’s click “<TD class=“DOCUMENT_LIST”><A href=“javascript:display2(0,16,0)”><IMG src=“buttonDisplay.gif” border=“0” alt=“Show”></A></TD>”.

-First Sequence file -> Completely works! td in every row always has A tag.

FindChildren
-Input: ”<webctrl tag=‘TD’ classname=‘PROJECT_NAME’ />"
-Selector:<html htmlwindowname=‘HTMLWINDOWNAME2’ title=‘TITLENAME’ />
<webctrl aaname=’*’ css-selector=‘body>table>tbody>table’ tag=‘TABLE’ />
-Options
–FIND_DESCENDANTS
-Output
–Children: ReturnedChildren

ForEach<UiPath.Core.UiElement> “Foreach row in ReturnedChildren”
-Misc
–TypeArgument:UiPath.Core.UiElement
–Values:ReturnedChildren

UiPath.Core.Activities.Click
-Target
–Element:row.FindFirst(FindScope.FIND_DESCENDANTS,new Selector("<webctrl tag=‘A’ />"))

-Second Sequence file -> I’m working on it yet… Not every td in rows always have A tag.

FindChildren
-Input: ”<webctrl tag=‘TD’ classname=‘DOCUMENT_LIST’ />"
-Selector:<html htmlwindowname=‘HTMLWINDOWNAME2’ title=‘TITLENAME’ />
<webctrl aaname=’*’ css-selector=‘body>table>tbody>table’ tag=‘TABLE’ />
-Options
–FIND_DESCENDANTS
-Output
–Children: ReturnedChildren

ForEach<UiPath.Core.UiElement> “Foreach row in ReturnedChildren”
-Misc
–TypeArgument:UiPath.Core.UiElement
–Values:ReturnedChildren

and then if is_link is true - Boolean type -,

UiPath.Core.Activities.Click
-Target
–Element:row.FindFirst(FindScope.FIND_DESCENDANTS,new Selector("<webctrl tag=‘A’ />"))

The Second sequence file fails, because the 4th column does not always have A tag, so it fails in the 4th <tr>.
Is there any way to skip Click activity if there is (or is not) any element in in ForEach loops?
I tried ElementExists activity to check if every TD tag have A tag before Click activity, it fails.

UiPath.Core.Activities.UiElementExist
-Target
–Element:row.FindFirst(FindScope.FIND_DESCENDANTS,new Selector("<webctrl tag=‘A’ />"))
-Output
–Exists: is_link

Thank you,


#17

are there anyone who can help me, please?


#18

I found the solution to skip “<td></td>” which doesn’t have a href link.

The solution is simply to surround the activity with try-catch, and carefully catch Exception.
If you don’t handle Exception properly, you’ll got Exception Error and the error stop foreach loop.

Try
    Element Exists
    -Element: row.FindFirst(FindScope.FIND_DESCENDANTS,new Selector("<webctrl aaname='Show' tag='IMG' />"))
Catch
    SlectorNotFoundException

hope it helps.


#19

Were you able to get this resolved? I’m trying to do something very similar and struggling. i was wondering if you did get this resolved if you would share the xmal with me?


#20

I can show you some later. Please wait a moment.