If you inspect the element, you will notice that the fields you want to edit are inside a iframe, whose source is /proc/sistema_push/. Therefore, to reference the email and password fields, you need to first reference the iframe. To fetch the iframe, let’s iterate the page iframes, and compare the URL. Note that the attribute src contains a relative path, but the value returned by the attribute URLof iframe is absolute, so we will add the domain of the Court’s website in the comparison term.
I will only add a variable (Cont) and an instruction block for.
Come on:
Sub MacacoLoko()
Dim IE As InternetExplorer
Dim docHTML As HTMLDocument
Dim Ulogin As Boolean, ieForm
Dim NumProc As String: NumProc = Me.ComarcaProcesso
Dim Email As String: Email = "[email protected]"
Dim Senha As String: Senha = "123456"
Dim Cont As Variant 'Vai ser o marcador para iterar as iframes em busca da correta (embora esse site só tenha uma, outros sites de tribunais podem ter mais, ou o site pode ser reformulado)
Set IE = New InternetExplorer
Set IE = CreateObject("InternetExplorer.Application")
'Abre o IE maximizado.
IE.Visible = True
IE.navigate "http://www.tjrs.jus.br/site/processos/tjrs_push/"
apiShowWindow IE.Hwnd, SW_MAXIMIZE
'Espera até que a página esteja totalmente carregada.
Do Until IE.readyState = READYSTATE_COMPLETE
Loop
'Itera as iframes, buscando a correta (no nosso caso, procuraremos pelo atributo "src" da tag "iframe".
For Each Cont In IE.Document.getElementsByTagName("iframe")
If Cont.src = "http://www.tjrs.jus.br/proc/sistema_push/" Then Set docHTML = Cont 'Atribuímos docHTML à iframe correta. Importante: O atributo "src" no HTML da página está em caminho relativo, mas a URL da frame tem que ser buscada com a URL completa.
Next Cont
'Nessa parte você deve conhecer a propriedade "name" dos elementos input do site que irá logar.
docHTML.all("email").innerText = Email
docHTML.all("senha").innerText = Senha
'Nessa parte você deve informar o nome (propriedade name) do formulário a ser submetido.
IE.Document.all("login").Click
'Daqui pra frente eu não testei; talvez seja necessário reatribuir o "dochtml", caso o número do processo esteja dentro de outra iframe, mas você já entendeu como se faz isso.
Do
'Coloca o nome do campo usuário do form na página.
IE.Document.all("input_num_themis").innerText = NumProc
DoCmd.GoToRecord , , acNext
Loop
End Sub
This code does not work because it is inside an iframe. Try to automate by this site: http://www.tjrs.jus.br/proc/sistema_push/
– danieltakeshi
It worked! How do I identify this path on other sites?
– gabrielpn06
Each site has its peculiarities... In the case of this tjrs, they possessed this path within the code of iframe. But usually they do not, so you would have to discover the hierarchy of the site and use another "type" of code. How in this example, where links are within frames...
– danieltakeshi
got it. thanks a lot for your help!
– gabrielpn06