【问题标题】:How to click button when navigating website?浏览网站时如何点击按钮?
【发布时间】:2020-12-31 03:13:07
【问题描述】:

我正在尝试打开网站、登录、选择报告并以 Excel 格式保存。

我设法打开 IE,导航到该站点,输入用户名/密码并登录。

如何选择网页按钮打开报告页面?

以下是我尝试单击的网站上的按钮部分和我尝试过的代码,两者都没有给出任何错误消息,它们根本不做任何事情。

网站 HTML

Sub vbamacro()
    
    Dim IE As Object
    Dim IEPage As Object
    Dim IEPageElement As Object
    
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    
    'Enter website name below
    
    IE.Navigate "websitename"
    
    'Ready state means wait until the website has loaded
    
    Do Until IE.ReadyState = 4
        DoEvents
    Loop
    
    Set IEPage = IE.Document
    
    Set IEPageElement = IEPage.getElementById("ctl00__contentPlaceHolder__txtUserID")
    IEPageElement.Value = "username"
    
    Set IEPageElement = IEPage.getElementById("ctl00__contentPlaceHolder__txtPassword")
    IEPageElement.Value = "password"
    
    Set IEPageElement = IEPage.getElementById("ctl00__contentPlaceHolder__btnLogin")
    IEPageElement.Click
    
    Do Until IE.ReadyState = 4
        DoEvents
    Loop
    
    With IE.Document
    
        Set elems = .getElementsByTagName("Li")
        For Each e In elems
    
            If (e.getAttribute("ID") = "Reports3") Then
                e.Click
                Exit For
            End If
    
        Next e
    
    End With
    
End Sub

也试过了;

For each e in ie.document.getElementsByTagName("Li") 
    If e.ID = "Reports3" Then
        e.Click
        Exit For
    End If
Next

【问题讨论】:

    标签: vba internet-explorer


    【解决方案1】:

    尝试直接导航到所需元素的 href

    IE.navigate(e.href)
    

    同样你点击“Li”标签元素,你必须得到Li子标签,女巫是“a”(具有href属性的那个)

    【讨论】:

    • 感谢工作!好像我让它变得更复杂,然后它需要是
    猜你喜欢
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 2019-11-28
    相关资源
    最近更新 更多