问题
I'm currently looking for a way to click on a button on a web page to automate an export.
I've already succeeded with logging in to the web page and clicking on the login button to redirect the page, but then I could not click on the next button i'm looking for.
My code :
For Each ele In IE.document.getElementsByTagName("ul")
If ele.document.getElementsByTagName("a").getAttribute("aria-labelledby") = "Exporter vers CSV" Then ele.Click
Next
Website source:
<ul class="dropdown-menu pull-left">
<!-- ngRepeat: item in secondaryItems track by item.dataAid --><li ng-repeat="item in secondaryItems track by item.dataAid" class="">
<a role="button" ng-show="item.visible" aria-labelledby="Exporter vers CSV" data-aid="tool-bar-inner-dd-btn-export" type="submit" ng-disabled="!item.enabled" ng-class="{plToolbarItemDisabled:!item.enabled, disabled:!item.enabled}" class="grid-export-item-btn" ng-click="item.callback(item, $event)" pl-toolbar-button-in-dropdown="" item="item">
回答1:
I cannot test it without knowing your URL, but this maywork:
For Each ele In IE.document.getElementsByTagName("ul")
For Each ele2 In ele.getElementsByTagName("a")
If InStr(ele2.InnerHtml, "aria-labelledby=""Exporter vers CSV""") Then ele2.Click
Next ele2
Next ele
回答2:
Give this a go. When you are upon instr()
function then simply the below method should get you there.
For Each ele In IE.document.getElementsByTagName("a")
If InStr(ele.getAttribute("aria-labelledby"), "Exporter vers CSV") > 0 Then ele.Click: Exit For
Next ele
来源:https://stackoverflow.com/questions/47791338/use-vba-to-click-on-a-button-in-ie