VBA [Internet Explorer] - 按钮提交(登录)

标签 vba excel

我需要一些关于如何通过 VBA 代码按下按钮的指导。这是在使用下面的代码之前完成的:(请参阅注释“<-----”,看看我卡在哪一行。)

WWW = "http://sezv... ' I can't provide the address since it is on a server.

Set IE = New InternetExplorerMedium
IE.Visible = True
IE.Navigate WWW              
StartDate & EndDate

Do
    If IE.READYSTATE = 4 Then
        Exit Do
    Else
        DoEvents
    End If
Loop

With IE.Document
    .getElementById("Username").Value = "Test"  'Username 
    .getElementById("Password").Value = "Test2" 'Password
    .all("Logga in").Click                      ' <---------
End With

HTML 看起来像这样:
<input name="Logga in" class="button right" type="submit" value="Logga in"/>
我将如何使用看起来像这样的按钮来执行此操作?:
<button class="REGISTRATION_FORM-Button" style="border-top-color: currentColor; border-right-color: currentColor; border-bottom-color: currentColor; border-left-color: currentColor; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; background-image: url("http://sezvm1091:9090/ais/images/buttonBackground.gif"); background-attachment: scroll; background-repeat: no-repeat; background-position-x: 0px; background-position-y: -50px; background-size: auto; background-origin: padding-box; background-clip: border-box; background-color: transparent;" type="button">

据我所知,这可能与某些脚本有关,如果是,我能否获得一些指导以了解如何找到它并将其实现到上面的代码中?
我很想分享脚本代码,但它是 70207 行。

最佳答案

要找到您可以使用的按钮,例如querySelector您可以在其中指定元素名称和类名称。

Dim btn As HTMLButtonElement
Set btn = IE.document.querySelector("button[class=REGISTRATION_FORM-Button]")
btn.Click

如果有更多具有相同类的按钮,如下所示:
<button title="Klarmarkera (ctrl+K)" class="ACTION_BUTTON-Button" style="border-top-color" type="button" >Klarmarkera (ctrl+K)</button>
<button title="Nytt samtal (ctrl+S)" class="ACTION_BUTTON-Button" style="border-top-color" type="button" >Nytt samtal (ctrl+S)</button> 

那么更多的属性可以用于querySelector例如title :
Set btn = IE.document.querySelector("button[class=ACTION_BUTTON-Button][title='Nytt samtal (ctrl+S)']")

如果出现更多类名,如下所示:
<button class="FancyButton FancyButton-ACTION_FORM-Button" style="border-top-color" type="button">Fancy Form Button</button>
querySelector可能看起来像这样:
Set btn = IE.document.querySelector("button[class='FancyButton FancyButton-ACTION_FORM-Button']")

关于VBA [Internet Explorer] - 按钮提交(登录),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43652353/

相关文章:

excel - 如何在 Excel 2007 中从 VBA 访问复选框

excel - 将矩阵从 Stata 12 导出到 Excel 或 MATLAB

excel - 如何使用VBA保护Excel工作簿?

c# - 如何使用 OpenXML 从 Excel 工作表中检索选项卡名称

vba - 将方程符号发送到 If 语句

vba - PowerPoint VBA : which command (or a set of commands) would create ppt frames out of my . jpg 图片?

vba - WorksheetFunction.CountA 没有返回正确的值

arrays - 构建和比较数组

vba - Range.Horizo​​ntalAlignment = 1在Excel中是什么意思

java - 使用 Apache POI 打开 xls 和 xlsx