Two hrefs with the same inner text

TNTScrub

New Member
Joined
Jan 7, 2021
Messages
14
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
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>

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
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top