1

In VBA I wondered if this possible to click on this HTML button without Id and Name attribute :

<ul aria-hidden="false" role="menu">
   <li>
        <button ..></button>
   </li>
   <li>
        <button ..></button>
   </li>
   <li> <!-- THE THIRD li, I would like to access this button -->
        <button title="exporter" role="menuitem" data-ng-disabled="myfunction()">my text</button>
  </li>
</ul>

For other elements with Id or a Name, here is how I do :

Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "site.com"
IE.document.getElementById("submitBtn").Click
// IE.document.getElementByName("submitBtn").Click

but in my previous example there is no "Id" or "Name" available, only a Title attribute for the button, is there any possibility to access this button ?

Any idea ?


Another way I tried but also not working :

the goal is to click the button, so I tried to execute directly "myfunction()", like this :

IE.document.parentWindow.execScript "myfunction()", "Javascript"

btu I get an execution error (error 80020101).. any idea ?

12
  • Yes, you can specify it as the nth child (childNodes[]) of an element that does have an id or name. Commented Jun 3, 2016 at 14:46
  • if the HTML is valid XML, you could also use XPath to select nodes/attributes based on attributes, position or sibling. Commented Jun 3, 2016 at 14:48
  • Or GetElementsByTagname and loop through the returned collection until you find one with the correct title attribute. Commented Jun 3, 2016 at 14:55
  • thank you, and is it possible for example to access the button where "myfunction()" has been located, I mean, "myfunction" is call only there so is there a way to get the node directly from that? Commented Jun 3, 2016 at 14:56
  • 1
    And just a heads up (in anticipation of the next question). That site is using AngularJS, so if myfunction()is TRUE, the button will be disabled and unclickable. I've never tried to programmatically change and AngularJS attribute through IE Automation, so I'm not 100% sure if you can just set data-ng-disabled=FALSE or if you will have to force a false evaluation of myfuction(). Commented Jun 3, 2016 at 15:01

1 Answer 1

1

Have you tried to loop through the elements and see a possible way to retrive how it is being detected?

For Each element In IE.Document.all
If element.className = "exporter" Then
Set LookedElement = element 
Exit For
End If
Next

Other useful feature to set elements

Set elems = IE.Document.getelementsbytagname("exporter")
Set elems = IE.Document.getElementsByName("exporter")

It may be more useful to add the reference (References->Microsoft Internet Controls) so you can see all the commands available for IE instead of late binding.

Sign up to request clarification or add additional context in comments.

1 Comment

yes and for those who didn't see this reference like me before, shdocvw.dll is simply missing, import it from your system32 files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.