【问题标题】:Pass value to textbox in website using Excel VBA使用 Excel VBA 将值传递给网站中的文本框
【发布时间】:2018-10-23 13:00:40
【问题描述】:

我正在尝试浏览网站并根据 Excel 的输入执行活动。

我一直在将值传递给输入元素,该元素会根据我们传递的值在下一个文本框中自动填充值(例如:如果我在目标框中传递邮政编码,则城市名称会自动填充在下一个框中)。我可以传递值,但它不会触发自动填充值的 JS。

网页中的目标框代码

<input name="zipcode" class="inputBoxRequired" id="zipcode"     onkeypress="return isNumberKey(event)" onblur="getZipCity(this.value,'/ProviderPortal')" type="text" size="46" maxlength="5">

代码尝试

Set Zip = ie_Doc.getElementById("zipcode")
 Zip.Value = Zip_Code 'Here value gets updated but associated js is not triggered
 ie_Doc.getElementById("zipcode").Focus

甚至尝试过火灾事件

Zip.FireEvent ("onchange")

在网页中它被称为 Onkeypress 事件。我用谷歌搜索找到解决方案,但我找不到确切的解决方案。

【问题讨论】:

  • 可以分享一下网址吗?
  • 抱歉@QHarr 它是一个安全的门户网站我无法分享网址,需要登录才能查看我正在浏览的页面。
  • 你也触发了 onBlur 吗?对于其中一些事情,他们希望按键最能被 .Focus 先模仿,然后 .Sendkeys "Text"..... 就像 sendkeys 一样可怕。
  • 请问应该怎么做
  • Zip.FireEvent ("onkeypress") : Zip.FireEvent ("onblur")

标签: html excel vba web-scraping


【解决方案1】:
Zip.FireEvent ("onkeypress")
Zip.FireEvent ("onblur")  '<== Apparently this did the trick

这些是显示的事件。

【讨论】:

  • 为什么这个答案没有得到与收到的问题相同的支持?再次找到@QHarr 的好消息。
【解决方案2】:

我遇到了同样的情况来验证这篇文章的解决方案,而在我的情况下,我没有“onblur”标签,所以我做了一些搜索并想出了一个解决方案。

Dim event_onChange As Object
Set event_onChange = ie_Doc.createEvent("HTMLEvents")
event_onChange.initEvent "keypress", True, False
Zip.dispatchEvent event_onChange

它将帮助面临同样问题的其他人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 2017-08-14
    相关资源
    最近更新 更多