Hello VBA heroes,
I have a working code that enters a cell value on a web page and clicks the search button. At the bottom of the page is the option to view or update the record that I've entered. I've managed to make a code click on the link using inner text. The problem is that I can have multiple hrefs with the same inner text or sometimes there is no href at all. How do I get my code to choose the specific href rather than the inner text? Below is the two of the hrefs Im looking at and my code. Id like to know how to click on the second one specifically.
<a href="javascript:__doPostBack('DataGrid2$ctl02$ctl00','')">View/Update</a>
<a href="javascript:__doPostBack('DataGrid2$ctl03$ctl00','')">View/Update</a>
I have a working code that enters a cell value on a web page and clicks the search button. At the bottom of the page is the option to view or update the record that I've entered. I've managed to make a code click on the link using inner text. The problem is that I can have multiple hrefs with the same inner text or sometimes there is no href at all. How do I get my code to choose the specific href rather than the inner text? Below is the two of the hrefs Im looking at and my code. Id like to know how to click on the second one specifically.
<a href="javascript:__doPostBack('DataGrid2$ctl02$ctl00','')">View/Update</a>
<a href="javascript:__doPostBack('DataGrid2$ctl03$ctl00','')">View/Update</a>
VBA Code:
Sub makeitup()
Dim ie As Object
Set ie = GetIE
On Error Resume Next
ie.Visible = True
TagN = ActiveCell.Value 'Tag Number
If Not IsEmpty(TagN) Then
ie.document.all("txtNumber").Value = TagN
ie.document.all("butQuickSearch").Click
End If
Application.Wait (Now + TimeValue("0:00:02"))
Set HTML = ie.document
Set ElementCol = HTML.getElementsByTagName("a")
For Each link In ElementCol
If link.innerHTML = "View/Update" Then
link.Click
End If
Next
End Sub