Link to home
Start Free TrialLog in
Avatar of J P
J P

asked on

Click on Hyperlink for TD Object

Hi all

I want to click on a hyperlink on a webpage using VBA that I have found using the below method:

 Set trs = ie.document.getElementsByTagName("tr")

For Each trObj In trs


    Set tds = trObj.getElementsByTagName("td")

    For Each tdObj In tds


           If tdObj.className = "btn_container" And tdObj.innerText = "Reinstate Award" Then

              tdObj.Click

            End If


    Next
Next

Open in new window


I can't get the tdObj.Click bit to click the hyperlink.

The html is below:

<td class="btn_container">


<input name="_linkSubmit" type="hidden"><a name="assessment_Reinstate" class="button_link" id="assessment_Reinstate" onclick="javascript:return disableLinks(this.href);" href='javascript:submitLink(document.Form0,"assessment_Reinstate");' type="button" renderer="uk.co.slc.tapestry.link.PortalLinkRenderer@1a79ffb">Reinstate Award</a>

</td>

Open in new window


Any help would be greatly appreciated.

Thanks in advance.

Jim
ASKER CERTIFIED SOLUTION
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of J P
J P

ASKER

Wonderful! Thanks Zakaria!

I just had to change the formatting slightly to:

tdObj.getElementsByTagName("a")(0).Click

Open in new window


Can you explain how it works?

Jim
Avatar of J P

ASKER

Thanks a million!
tdObj represent the table column `td` that you can't click it using Click since it has no click event attached or href to redirect to.

To click the anchor inside this td you need to select the anchor <a> first using the `getElementsByTagName('a')` method that returns an HTMLCollection of elements with the given tag name (<a>), then we use `(0)` to select the first one and finally Click to trigger the redirection.
You're welcome, glad to help sir.