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">
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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)
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0
No, it should select the second element - the collection returned by GetElementsByClassName is zero-indexed.
 
Upvote 0
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.
 
Upvote 0
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: 3
Upvote 0
Hi, have you checked the code shared by Norie ?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

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