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:
I can't get the tdObj.Click bit to click the hyperlink.
The html is below:
Any help would be greatly appreciated.
Thanks in advance.
Jim
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
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>
Any help would be greatly appreciated.
Thanks in advance.
Jim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
To click the anchor inside this td you need to select the anchor <a> first using the `getElementsByTagName('a')
You're welcome, glad to help sir.
ASKER
I just had to change the formatting slightly to:
Open in new window
Can you explain how it works?
Jim