click button without id on vba to use on IE

2019-07-25 00:29发布

I'm trying to made a click on a button that does not have an ID or a Name; I tried using tabs, but it didn't work, and I tried the following code, but it doesn't do anything:

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

And here is the HTML markup:

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

1条回答
男人必须洒脱
2楼-- · 2019-07-25 01:21

The tagx.Value is always empty. Check Html-Button Value attribute information here.

The buttons seems to have Span with text Save or Cancel inside of it so you could check for tagx.innerText to find the save button and then call Click method on it.

Set tags = ie.document.getElementsByTagName("button")
For Each tagx In tags
    If tagx.innerText = "Save" Then
        tagx.Click
        Exit For
    End If
Next
查看更多
登录 后发表回答