I am trying to access a web page with a macro in Excel, enter a code in an input, press a button and copy the price resulting from the search. It is this last step that I do not achieve. The element that contains the price has the id #result_ok but one of the drawbacks is that it is a text node that does not end up being inside anything and at the same time has three brothers. I show you:
I have tried to do a getElementById and access its innerText or innerHTML and nothing ... It gets code that does not correspond to its inner text or several errors when trying other things.
Sub buscar()
Dim IE As InternetExplorer
Dim DOC As HTMLDocument
Dim url As String
Set IE = Nothing
Set DOC = Nothing
url = "http://www.salvadorescoda.com/tarifas/index.htm"
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate url
While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE
DoEvents
Wend
Set DOC = IE.document.frames
Dim iFrameDoc As HTMLDocument
Set iFrameDoc = DOC.Item("mainFrame").document 'especificamos el nombre del frame
If iFrameDoc Is Nothing Then
MsgBox "No existe ningún frame con el nombre especificado."
IE.Quit
Set IE = Nothing
Exit Sub
End If
Dim itemEle As Object
'ya estamos en el frame, ahora podemos conseguir el elemento INPUT
For Each itemEle In iFrameDoc.getElementsByTagName("input")
If itemEle.getAttribute("class") = "campocodigo" Then
itemEle.Value = ActiveCell.Value
Exit For
End If
Next
'buscamos y clickamos el botón buscar
For Each itemEle In iFrameDoc.getElementsByTagName("input")
If itemEle.getAttribute("class") = "floatright botonbuscar" Then
itemEle.Click
Exit For
End If
Next
'¿Como obtengo el texto?
ActiveCell.Offset(0, 1).Value = iFrameDoc.getElementsById("result_ok").innerHTML
'IE.Quit
'Set IE = Nothing
End Sub
Do you know what the problem is? How can I get it? Thank you very much in advance!