如何在HTML代码中使用VBA调用onClick? [英] How to call onClick with VBA in HTML code?

查看:109
本文介绍了如何在HTML代码中使用VBA调用onClick?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在HTML页面中调用 onClick ?

How can I call onClick in a HTML page?

使用Google,我收到了以下代码:

Using Google, I got this code:

<img src="Imagens/lupa.gif" alt="Pesquisar Pasta" class="img" onclick="localizar();">

我正在使用此VBA代码:

I'm using this VBA code:

Sub FazerLoginSite()

Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
With IE
    .Visible = True
    .Navigate ("https://webseal.itau/j146/pjuridico/")
    While .Busy Or .ReadyState <> 4: DoEvents: Wend
    On Error Resume Next
    .document.getElementById("username").Focus
    .document.getElementById("username").Value = "987268556"

    .document.getElementById("password").Focus
    .document.getElementById("password").Value = ""

    .document.All("button1").Click
    On Error GoTo 0
    While .Busy Or .ReadyState <> 4: DoEvents: Wend

    While .Busy Or .ReadyState <> 4: DoEvents: Wend
    .document.getElementById("pasta").Focus
    .document.getElementById("pasta").Value = "140200586125"
    While .Busy Or .ReadyState <> 4: DoEvents: Wend
   
    While .Busy Or .ReadyState <> 4: DoEvents: Wend
    Set allInputs = IE.document.getElementsByTagName("input")
    For Each element In allInputs
        If element.getAttribute("src") = "Imagens/lupa.gif" Then
            element.invokemember ("OnClick")
            Exit For
        End If
    Next element
    While .Busy Or .ReadyState <> 4: DoEvents: Wend

    Debug.Print .LocationURL
End With

End Sub

如何单击此代码?在网站上,这是一张图片,我在代码的第一部分中设置了我的登录名和密码,我输入了一个要搜索的数字,这里称为"Pasta",最后我试图单击该图片./p>

How can I click on this code? In the web site this is an Image and the first part of the code I set my login and password, the I put a number to search, here called "Pasta", and finally I'm trying to click on this image.

推荐答案

不需要任何查找元素的元素.您可以使用 execScript()函数调用与 onClick 相同的JavaScript函数:

There shouldn't be any need to find the element. You can just call the same JavaScript function that onClick is calling using the execScript() function:

IE.document.parentWindow.execScript "localizar();", "javascript"

这篇关于如何在HTML代码中使用VBA调用onClick?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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