Form.Submit不会在使用VBA时通过 [英] Form.Submit does not go through when using VBA

查看:197
本文介绍了Form.Submit不会在使用VBA时通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我正从中提取数据的网页。我可以使用VBA做一切都好,除了点击一个图像元素,然后提交一个表单,并创建一个弹出数据。



图像元素中的一个属性称为productguid,并具有字符串值=



a1​​2-545。



格式的HTML代码看起来像这样,我用鼠标点击图像元素。

 < form id =GetProductQuantitiesForAccessibleBranchesaction =GetProductQuantitiesForAccessibleBranchesmethod =post> 
< input type =hiddenname =ProductGuidvalue =>
< / form>

这是HTML代码,我用鼠标手动点击它:

 < form id =GetProductQuantitiesForAccessibleBranchesaction =GetProductQuantitiesForAccessibleBranchesmethod =post> 
< input type =hiddenname =ProductGuidvalue =a12-545>
< / form>

根据这一点,我假设image元素中的productguid值被传递到表单之前提交。
这是我的VBA代码如下所示:

 '更改输入元素值
ie。 document.getElementById(GetProductQuantitiesForAccessibleBranches)。all.item(0).value =a12-545

'提交表单
ie.Document.getElementyId(GetProductQuantitiesForAccessibleBranches)。提交

根据本地窗口,所有Javascript事件都是 Null 。这两行代码运行没有任何错误,但网页不更新。我在这里缺少一些东西吗?



我也尝试用 .Click 方法点击图像元素,但是



该网页受密码保护,因此我无法公开发布该网址。



更新:



这是标签中的HTML,通常是手动单击,然后提交表单。也许这里有东西可以使用?

 < img alt =查看其他位置的数量src = /WebOrder/Images/CheckQtys.gif
title =查看其他位置的数量class =popup
popupdirection =upperleftpopupwidth =380
popupcontent =#ProductQuantitiesForAccessibleBranches
onbeforepopupcreate = onBeforePopupCreate_GetProductQuantitiesForAccessibleBranches(这)
popupajaxformid = GetProductQuantitiesForAccessibleBranches
onbeforepopupajaxpost = onBeforePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(这)
oncompletepopupajaxpost = onCompletePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(这)
productguid =a12-545
displayitem =33902
brandguid =00000000-0000-0000-0000-000000000000
brandname =brandsku =>


解决方案

给这个镜头,我怀疑这是成为完美的答案,而不实际看到网站。但是,假设您没有任何框架/ iframe(请确认没有任何框架),那么应该找到正确的图片标签,并且应该单击它。

  Public Sub Click_IMG_Tag()
Dim Elements As Object
Dim Element As Object

'获取一个指针IE等等,我假设这已经完成

设置元素= IE.Document.getElementsByTagName(img)

元素中的每个元素
On Error Resume Next'用于绕过不具有.Title属性
'的元素,您应该错误处理此异常
如果Element.Title =查看其他位置的数量,然后
Element.Focus
Element.Click
Element.FireEvent(OnClick)
IELoad IE
退出
结束如果
下一个

End Sub

公共子IELoad(浏览器作为对象)
而Browser.busy或Browser.Readystate<> 4
Application.Wait(Now()+ TimeValue(00:00:01))
DoEvents
Wend
End Sub


I have a webpage that I am extracting data from. I can do everything fine with VBA apart from clicking on an image element which then submits a form and a popup with data is created.

One of the attributes in the image element is called "productguid" and has a string value =

"a12-545".

The HTML code of the form looks like this BEFORE I click on the image element with my mouse.

<form id="GetProductQuantitiesForAccessibleBranches" action="GetProductQuantitiesForAccessibleBranches" method="post">
  <input type="hidden" name="ProductGuid" value="">
</form>

This is the HTML code AFTER I manually click on it with the mouse:

<form id="GetProductQuantitiesForAccessibleBranches" action="GetProductQuantitiesForAccessibleBranches" method="post">
  <input type="hidden" name="ProductGuid" value="a12-545">
</form>

Based on this I assumed that the productguid value from the image element gets passed onto the form before it is submitted. Here is what my VBA code looks like this:

'Change the input element value
ie.Document.getElementById("GetProductQuantitiesForAccessibleBranches").all.item(0).value = "a12-545"

'Submit the form
ie.Document.getElementyId("GetProductQuantitiesForAccessibleBranches").Submit

According to the Locals window, all the Javascript events are Null. Both lines of code run without any errors but the webpage does not update. Am I missing something here?

I have also tried just clicking the image element with the .Click method, but that doesn't do anything either.

The webpage is password protected so I cannot post the URL publicly.

UPDATE:

Here is the HTML in the tag that normally is clicked manually which then submits the form. Perhaps there is something in here that I can use?

<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="">

解决方案

Give this a shot, I doubt this is going to be the 'perfect' answer without actually seeing the site. However, this should find the correct image tag, assuming you don't have any frames/iframes (please check there aren't any), and should click it.

Public Sub Click_IMG_Tag()
    Dim Elements As Object
    Dim Element As Object

    'Get a pointer to IE etc first, I'm assuming this is already done

    Set Elements = IE.Document.getElementsByTagName("img")

    For Each Element In Elements
        On Error Resume Next ' used to bypass elements that don't have .Title property
                             ' later, you should error handle this exception
        If Element.Title = "View Quantities At Other Locations" Then
            Element.Focus
            Element.Click
            Element.FireEvent ("OnClick")
            IELoad IE
            Exit For
        End If
    Next

End Sub

Public Sub IELoad(Browser As Object)
    While Browser.busy Or Browser.Readystate <> 4
        Application.Wait (Now() + TimeValue("00:00:01"))
        DoEvents
    Wend
End Sub

这篇关于Form.Submit不会在使用VBA时通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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