2016-09-27 18 views
1

我想點擊一個沒有ID或名稱的按鈕;我試着用標籤,但它沒有工作,我嘗試下面的代碼,但它不會做任何事情:單擊按鈕無需身份證上的ID使用IE瀏覽器

Set tags = Ie.document.getElementsByTagName("button") 
For Each tagx In tags 
    If tagx.Value = "Save" Then 
     tagx.onclick 
     Exit For 
    End If 
Next 

這裏是HTML標記:

<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"> 
    <div class="ui-dialog-buttonset"> 
    <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Cancel</span></button> 
    <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Save</span></button> 
    </div> 
</div> 

回答

0

tagx.Value總是空的。檢查Html-Button Value屬性信息here

的按鈕似乎有Span文本保存取消它內部的,所以你可以檢查tagx.innerText找到保存按鈕,然後調用Click方法就可以了。

Set tags = ie.document.getElementsByTagName("button") 
For Each tagx In tags 
    If tagx.innerText = "Save" Then 
     tagx.Click 
     Exit For 
    End If 
Next 
+0

迪謝謝你,它的作品完美 - 問候 –

+0

@gpmn我很高興它幫助:)。請將答案標記爲已接受。 – dee

相關問題