2016-08-23 63 views
5

我有一個網頁,我正在從中提取數據。除了點擊一個圖像元素,然後提交一個表單並創建一個帶有數據的彈出窗口,我可以用VBA做一切正常工作。使用VBA時,Form.Submit不通過

在一個圖像元素的屬性被稱爲「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> 

基於此我假定從圖像元件的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 

據當地人窗口,所有的JavaScript事件Null。這兩行代碼無任何錯誤地運行,但網頁不會更新。我在這裏錯過了什麼嗎?

我也試過用.Click方法點擊圖片元素,但是也沒有做任何事情。

該網頁受密碼保護,因此我無法公開發布該網址。

UPDATE:

這裏是在通常被手動地點擊,然後提交表單的標記的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=""> 
+0

如果一個頁面元素的值正在改變基於一個點擊事件,我敢打賭,所有的javascript事件都不爲空。 IE對象可能由於某種原因未顯示某些事件,但深入研究該JavaScript無疑將成爲理解正在發生的事情的關鍵。通過例如自己調查頁面上的腳本/事件您最喜愛的瀏覽器的開發控制檯。我也強烈建議添加javascript和/或dom標籤來獲得這裏的一些專家。 – Mikegrann

+0

噢,謝謝。我厭倦了使用Chrome Dev,但是我很難理解我在看什麼......如果我點擊網絡選項卡,在啓動器列中,我看到一個腳本,然後當我將它鼠標懸停時,整個列表不同的事情出現。我該怎麼處理這些信息? – TheGuyOverThere

+0

設置值如下:'ie.Document.getElementById(「GetProductQuantitiesForAccessibleBranches」)。getElementsbyName(「ProductGuid」)(0).Value =無論什麼工作 –

回答

3

給這個鏡頭,我懷疑這將是沒有真正看到該網站的'完美'的答案。但是,這應該找到正確的圖像標籤,假設您沒有任何框架/ iframe(請檢查沒有任何),並且應該單擊它。

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 
+0

我正要回答類似的問題。我曾經遇到同樣的問題,然後不得不遍歷所有按鈕並檢查具有特定標籤的按鈕,然後單擊它。這對我來說似乎是一個很好的答案。 IE自動化與vba無論如何是一個痛苦的屁股。做得好! – Mafii

+0

感謝您的反饋! –

+0

感謝您的努力,我知道您已經花了相當多的努力試圖幫助我弄清楚這一點,但這也行不通。代碼運行正常,但網頁不更新。我完全沒有想法。 – TheGuyOverThere