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
J PAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Zakaria AcharkiAnalyst DeveloperCommented:
Try to select the anchor first then click it like :

tdObj.getElementsByTagName('a')[0].Click

Open in new window


You could use `querySelector()` too like :

tdObj.querySelector('a').Click

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
J PAuthor Commented:
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
J PAuthor Commented:
Thanks a million!
Zakaria AcharkiAnalyst DeveloperCommented:
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.
Zakaria AcharkiAnalyst DeveloperCommented:
You're welcome, glad to help sir.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.