VBA [Internet Explorer]-按钮提交(登录) [英] VBA [Internet Explorer] - Button Submit (Login)

查看:158
本文介绍了VBA [Internet Explorer]-按钮提交(登录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些有关如何通过VBA代码按下按钮的指导.这是在使用下面的代码之前完成的:(请参阅评论< -----",以查看我被困在哪一行.)

I need some guidance on how I can press a button through VBA code. This had been done before using the code below: (See comment "<-----", to see what line that that I am stuck at.)

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看起来像这样:

The HTML Looks like this:

<input name="Logga in" class="button right" type="submit" value="Logga in"/>

我将如何使用看起来像这样的按钮来做到这一点?:

How would I go about doing it with a button that looks something like this?:

<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行.

From what I know, this is probably connected to some Script, and if it is, can I get some guidance to how I can find it and implement it into the code above? I would love to share the Script code, but it is 70207 lines.

推荐答案

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

To find the button you could use e.g. querySelector where you can specify both the element name and class name.

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

如果有更多相同类别的按钮,则这样:

In case there are more butons with same class like this:

<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:

then more attributes can be used in querySelector e.g. title:

Set btn = IE.document.querySelector("button[class=ACTION_BUTTON-Button][title='Nytt samtal (ctrl+S)']")

如果出现更多的类名,例如:

In case when more class names are present like here:

<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]-按钮提交(登录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆