Need HTML help please....

TNTScrub

New Member
Joined
Jan 7, 2021
Messages
14
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I've been beating my head against my keyboard in frustration for at least 4 days trying to solve this. The HTML I'm forced to deal with has duplicate id issues. Can anyone tell me how to create a code that identifies or at least lets me click on the second one? These are the two lines of Code I'm dealing with.

<input name="butDelete" class="btn btn-danger" id="butDelete" type="submit" value="Delete">

<input name="butDelete" class="btn btn-primary" id="butDelete" type="submit" value="Delete This Cycle Record">
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,263
Office Version
  1. 365
Platform
  1. Windows
You could try using the name rather than the id.

Something like this where doc is a reference to the html document.
VBA Code:
Set btn = doc.GetElementsByName("butDelete")(1)
 

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
413
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi,

You can Check below code:
VBA Code:
Dim htmlobject As Object
Set HTMLDoc = ieBrowser.document
    For Each htmlobject In HTMLDoc.getElementsByTagName("input")
            If htmlobject.getElementByClassName = "btn btn-primary" Then
                htmlobject.Click
                Exit For
        End If
    Next
 

TNTScrub

New Member
Joined
Jan 7, 2021
Messages
14
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi,

You can Check below code:
VBA Code:
Dim htmlobject As Object
Set HTMLDoc = ieBrowser.document
    For Each htmlobject In HTMLDoc.getElementsByTagName("input")
            If htmlobject.getElementByClassName = "btn btn-primary" Then
                htmlobject.Click
                Exit For
        End If
    Next
Thanks for the quick reply.
Unfortunately using the "btn btn-primary" attribute also takes me to a completely different button that also precedes this one. The only unique identifier I can find is the "Value" attribute. Ill try and edit your code and see if it will work.
 

TNTScrub

New Member
Joined
Jan 7, 2021
Messages
14
Office Version
  1. 365
  2. 2019
Platform
  1. Windows

ADVERTISEMENT

You could try using the name rather than the id.

Something like this where doc is a reference to the html document.
VBA Code:
Set btn = doc.GetElementsByName("butDelete")(1)
Does the "(1)" dictate that it will select the first element with that name?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,263
Office Version
  1. 365
Platform
  1. Windows
No, it should select the second element - the collection returned by GetElementsByClassName is zero-indexed.
 

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
413
Office Version
  1. 365
  2. 2019
Platform
  1. Windows

ADVERTISEMENT

Thanks for the quick reply.
Unfortunately using the "btn btn-primary" attribute also takes me to a completely different button that also precedes this one. The only unique identifier I can find is the "Value" attribute. Ill try and edit your code and see if it will work.
Thanks for the response. If you share the URL, can create the exact code.
 

TNTScrub

New Member
Joined
Jan 7, 2021
Messages
14
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
This is the best I can offer. Its an internal company page and I'm absolutely certain you couldn't reach the url

<div class="col-lg-12">
<h1 class="page-header">Cycle Record</h1>
<h4></h4>
<h4></h4>

<div style="text-align: center;">
<div class="btn-group ">
<table>
<tbody><tr>
<td>
<input name="Button_Exit" class="btn btn-primary" id="Button_Exit" type="submit" value="Exit">&nbsp;
<input name="butSave" class="btn btn-primary" id="butSave" type="submit" value="Save">&nbsp;
<input name="butDelete" class="btn btn-primary" id="butDelete" type="submit" value="Delete This Cycle Record"></td>
</tr>
</tbody>
</table>


</div>
<br>
<h4><span class="label label-warning" id="lblMSG"></span></h4>
</div>
<br>
</div>
 

Attachments

  • Capture.PNG
    Capture.PNG
    15.5 KB · Views: 2

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
413
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi, have you checked the code shared by Norie ?
 

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
413
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Check with Value parameter.

VBA Code:
For Each htmlobject In HTMLDoc.getElementsByTagName("input")
            If htmlobject.value = "Delete This Cycle Record" Then
                htmlobject.Click
            Exit For
        End If
    Next
 

Watch MrExcel Video

Forum statistics

Threads
1,126,928
Messages
5,621,642
Members
415,849
Latest member
PhoenixRising2015

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
Top