【问题标题】:Call onclick JS event on website button using VBA使用 VBA 在网站按钮上调用 onclick JS 事件
【发布时间】:2017-02-03 16:15:32
【问题描述】:

我正在使用 VBA 与 IE 中的网站进行交互。

作为其中的一部分,我需要在那里单击一个按钮,但一个简单的.Click 不起作用,因为我需要触发此按钮后面的 JS onclick 事件

这里有人可以告诉我如何通过模拟点击并触发事件或直接调用 JS 事件来实现这一点吗?

这应该发生在下面的 VBA 代码之后。

我的 VBA 代码:

Dim IE As Object
Dim MyURL As String
Dim varResults As New DataObject

varResults.SetText TxtSql.Text
varResults.PutInClipboard
Unload FrmResults

Set IE = CreateObject("InternetExplorer.Application")

MyURL = "https://myFirstUrl"

IE.Navigate MyURL
IE.Visible = True

While IE.busy
    DoEvents
Wend

Application.Wait (Now + TimeValue("0:00:02")) ' to allow time for loading the page

按钮后面的onclick JS事件:

javascript:document.forms.jobProfileForm.action='https://mySecondUrl';document.forms.jobProfileForm.submit()

按钮的 HTML:

<input class="normalbttn" id="editProfileBttn" value="Edit Profile" onclick="theAboveJS" type="button"></input> 

【问题讨论】:

    标签: vba excel internet-explorer onclick


    【解决方案1】:

    试试这个:

    IE.Document.getelementbyid("editProfileBttn").fireevent ("onclick")

    【讨论】:

    • 谢谢,斯科特!我试过了,但没有区别 - 它不会触发按钮/事件,也不会加载带有 textarea 的页面。
    猜你喜欢
    • 2017-07-24
    • 1970-01-01
    • 2013-03-01
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    相关资源
    最近更新 更多