簡體   English   中英

使用VBA在網頁中填寫用戶名和密碼

[英]Fill user name and password in a webpage using VBA

這是我第一次嘗試通過VBA導航IE瀏覽器。 我想: - 轉到這個網頁https://hb2.bankleumi.co.il/e/Login.html - 填寫用戶名 - 填寫密碼 - 點擊“登錄”按鈕現在我得到了錯誤“對象'IWebBrowser2'的方法'文檔'失敗”

我試圖檢查網頁的html代碼中的元素並找到它們的ID,但我想我在調用方法或接近對象時犯了一些錯誤。

我的代碼是:

Option Explicit
Sub dataFromLeumi()
    Dim myPassword As String
    myPassword = "somepassword"
    Dim myUserName As String
    myUserName = "someusername"



    Dim loginPath As String
    loginPath = "https://hb2.bankleumi.co.il/e/Login.html"
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.application")
    IE.Visible = True
    IE.navigate loginPath

    Dim userName As Object
    Set userName = IE.document.getattribute("uid")
    userName.Item(0).Value = myUserName

    Dim password As Object
    password = IE.document.getelementbyid("password")
    password.Item(0).Value = myPassword


    IE.document.getelementbyid("enter").Click
End Sub

我應該在代碼中更改什么? 我錯過了什么?

謝謝!

嘗試這個

Sub test()
' open IE, navigate to the desired page and loop until fully loaded
    Set ie = CreateObject("InternetExplorer.Application")
    my_url = "https://hb2.bankleumi.co.il/e/Login.html"

    With ie
        .Visible = True
        .Navigate my_url
        .Top = 50
        .Left = 530
        .Height = 400
        .Width = 400

    Do Until Not ie.Busy And ie.readyState = 4
        DoEvents
    Loop

    End With

' Input the userid and password
    ie.Document.getElementById("uid").Value = "testID"
    ie.Document.getElementById("password").Value = "testPW"

' Click the "Search" button
    ie.Document.getElementById("enter").Click

    Do Until Not ie.Busy And ie.readyState = 4
        DoEvents
    Loop
End Sub

暫無
暫無

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

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