【发布时间】:2016-12-30 21:05:26
【问题描述】:
我有一个从中提取数据的网页。除了单击图像元素然后提交表单并创建包含数据的弹出窗口之外,我可以使用 VBA 完成所有操作。
图像元素中的一个属性称为“productguid”,具有字符串值 =
“a12-545”。
在我用鼠标单击图像元素之前,表单的 HTML 代码如下所示。
<form id="GetProductQuantitiesForAccessibleBranches" action="GetProductQuantitiesForAccessibleBranches" method="post">
<input type="hidden" name="ProductGuid" value="">
</form>
这是我用鼠标手动点击后的 HTML 代码:
<form id="GetProductQuantitiesForAccessibleBranches" action="GetProductQuantitiesForAccessibleBranches" method="post">
<input type="hidden" name="ProductGuid" value="a12-545">
</form>
基于此,我假设 image 元素中的 productguid 值在提交之前被传递到表单上。 这是我的 VBA 代码的样子:
'Change the input element value
ie.Document.getElementById("GetProductQuantitiesForAccessibleBranches").all.item(0).value = "a12-545"
'Submit the form
ie.Document.getElementyId("GetProductQuantitiesForAccessibleBranches").Submit
根据 Locals 窗口,所有的 Javascript 事件都是Null。两行代码运行没有任何错误,但网页没有更新。我在这里遗漏了什么吗?
我也尝试过使用.Click 方法单击图像元素,但这也无济于事。
该网页受密码保护,因此我无法公开发布网址。
更新:
这里是标签中的 HTML,通常手动单击然后提交表单。也许这里有什么我可以使用的?
<img alt="View Quantities At Other Locations" src="/WebOrder/Images/CheckQtys.gif"
title="View Quantities At Other Locations" class="popup"
popupdirection="upperleft" popupwidth="380"
popupcontent="#ProductQuantitiesForAccessibleBranches"
onbeforepopupcreate="onBeforePopupCreate_GetProductQuantitiesForAccessibleBranches(this)"
popupajaxformid="GetProductQuantitiesForAccessibleBranches"
onbeforepopupajaxpost="onBeforePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(this)"
oncompletepopupajaxpost="onCompletePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(this)"
productguid="a12-545"
displayitem="33902"
brandguid="00000000-0000-0000-0000-000000000000"
brandname="" brandsku="">
【问题讨论】:
-
如果页面元素的值根据点击事件发生变化,我敢打赌所有的 javascript 事件都不为空。 IE 对象可能由于某种原因没有显示某些事件,但深入研究该 javascript 肯定是了解正在发生的事情的关键。自己调查页面上的脚本/事件,例如您最喜欢的浏览器的开发控制台。我还强烈建议添加 javascript 和/或 dom 标记以吸引一些专家。
-
哦,好的,谢谢。我厌倦了使用 Chrome Dev,但我很难理解我在看什么......如果我点击 Networks 选项卡,在 Initiator 列中我会看到一个脚本,然后当我将鼠标悬停在它上面时,整个列表不同的东西出现。我应该如何处理这些信息?
-
设置值类似于:
ie.Document.getElementById("GetProductQuantitiesForAccessibleBranches").getElementsbyName("ProductGuid")(0).Value=Whatever应该可以工作 -
更改值很好,它可以做到这一点。提交是问题。发布请求根本不通过。
-
会不会像使用 submit() 而不是 Submit 一样简单?不是 100% 确定 VBA 如何发送 javascript 命令..
标签: javascript html vba dom browser-automation