簡體   English   中英

用於導航 IE 的 VBA 代碼不起作用

[英]VBA code for navigating IE is not working

首先,很抱歉文本中的任何錯誤,英語不是我的母語。 其次,我在互聯網上搜索了很多關於此的內容,但無法找到解決方案。 編程是我開始的愛好,如果問題是基本的,請提前抱歉。

所以,我正在構建一個代碼來導航到一個站點,填寫登錄名和密碼,進入該站點。 加載后,導航到另一個鏈接,select 是 Dropbox 中的一個選項。 然后我需要將文檔上傳到站點(單擊按鈕打開資源管理器以便我可以找到我想要的文件)並發送它。

我的代碼一直在工作,直到登錄后等待。 然后,當我必須導航到另一個鏈接時,代碼就結束了。

Public Sub test()
Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Dim oHTML_Element As IHTMLElement
Dim sURL As String

Const cUsername = "xxxxx"
Const cPassword = "xxxxx"

sURL = "https://sta.previc.gov.br/staweb/Login.xhtml"
Set oBrowser = New InternetExplorer
oBrowser.Visible = True
oBrowser.Silent = True
oBrowser.navigate sURL
'oBrowser.FullScreen = True

Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE

Set HTMLDoc = oBrowser.document
Do
' Wait till the document is loaded
Loop Until HTMLDoc.readyState = "complete"

HTMLDoc.getelementbyid("loginForm:usernameInput").Focus
HTMLDoc.getelementbyid("loginForm:usernameInput").Value = cUsername
HTMLDoc.getelementbyid("loginForm:passwordInput").Focus
HTMLDoc.getelementbyid("loginForm:passwordInput").Value = cPassword
HTMLDoc.getelementbyid("loginForm:j_idt30").Click


Do
' Wait till the document is loaded
Loop Until HTMLDoc.readyState = "complete"

For Each oHTML_Element In HTMLDoc.getElementsByTagName("a")
    If oHTML_Element.innerText = "Envio de arquivos" Then
        oHTML_Element.Click
        Do
        ' Wait till the document is loaded
        Loop Until HTMLDoc.readyState = "complete"
        Exit For
    End If
Next

End Sub

加載后我需要點擊的鏈接代碼在這個

關聯

我認為您需要在單擊登錄按鈕后手動中斷幾秒鍾。 我認為原因是,IE的就緒state在第一次加載頁面后仍然設置為完成。

單擊登錄按鈕后嘗試以下中斷 5 秒:

'Application.Wait (Now + TimeSerial(pause_hours, pause_minutes, pause_seconds))
Application.Wait (Now + TimeSerial(0, 0, 5))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM