Click on a variable ID

1

Good afternoon,

I'm doing a small macro as a bot, to enter data in a web page that I have to use repeatedly.

In the code I only need the last part, but I can not use getElementByID, since the ID is variable, I had thought of a couple of things to get through, but nothing that was good for a code (the Loops are not our friends).

Then I leave the code that I have written so far, and the code of the page, indicating the ID that I need to take:

  

Sub Declarar Sale ()

Dim ie As InternetExplorer
Dim pagina As HTMLDocument
Dim buscar As HTMLButtonElement
Dim chasis As String
Dim precio As Object

'Crea el explorador de internet
Set ie = New InternetExplorer

'Hacemos visible el explorador
ie.Visible = True

'Navega a la página de Cronos
ie.navigate "https://es-cronos.peugeot.com/dvnWeb/initVehicleArrival.action"

'Espera a que la página cargue
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE

'La página cargada la asignamos a la variable "pagina"
Set pagina = ie.document

' Recogemos los chasis para la declaración de llegada al concesionario
chasis = ""

For i = 2 To Range("B1").End(xlDown).Row

    chasis = chasis & Range("B" + CStr(i)).Value & ","

Next i

' Escribimos los chasis
pagina.getElementById("vehicleList").Value = chasis
' Escribimos la fecha
pagina.getElementById("arrivalDateId").Value = Range("C1").Value
' Siguiente página
pagina.getElementById("addNewArrivalLink").Click

' Esperamos
Application.Wait (Now + TimeValue("0:00:08"))

' Checkeamos los vehículos
pagina.getElementById("cb_itemsTable").Checked = True

Ok, now what I need is to give you a button, which has variable ID, I leave the code:

<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" id="anchor_1380069774" role="button" aria-disabled="false" style="font-size: 11px;" onclick="actionReportLaunched = true; startActionReportPoller();$('#openWaitActionReportDialogTrigger').trigger('click');hideActionReportCloseSpan();$('#waitActionReportTrigger').trigger('click');">
<span class="ui-button-icon-primary ui-icon ui-icon-check">
</span><span class="ui-button-text">
								Declarar llegada de vehículos

As you can see the ID is "anchor_XXXXXXXXXX" the number is always variable, and I do not know how to get to the ID property, to end up accessing "Click".

Thanks and regards!

    
asked by Curro Donaire Lopez 16.10.2017 в 17:47
source

2 answers

0

You can use the outerHTML method to extract the information from the label as a String and then look for some part of the text that helps you identify the button.

    
answered by 10.11.2017 в 02:16
0

Try a css selector to select the item.

css selector :

a[id^=anchor_]

"^" in CSS = the attribute starts with "anchor_"

pagina.querySelector("a[id^=anchor_]").Click
    
answered by 15.07.2018 в 11:47