How to click on a non-button IE object via VBA?

kbay808
kbay808 used Ask the Experts™
on
I'm trying to create a code that will click on an object called "List View" in an IE window.  Below are 2 examples of the code for the same object.  The object ID keeps changing.

Example# 1
<LI id=x-menu-el-ext-comp-396813 class=x-menu-list-item><A id=ext-comp-396813 class=x-menu-item hideFocus href="https://servman/sm/cwc/cwc_listdetail.jsp?thread=1#" unselectable="on"><IMG id=ext-gen65 class="x-menu-item-icon " alt="" src="https://servman/sm/js/extjs/resources/images/default/s.gif"><SPAN id=ext-gen66 class=x-menu-item-text>List View</SPAN></A></LI>

Open in new window


Example# 2
<LI id=x-menu-el-ext-comp-735337 class=x-menu-list-item><A id=ext-comp-735337 class=x-menu-item hideFocus href="https://servman/sm/cwc/cwc_listdetail.jsp?thread=1#" unselectable="on"><IMG id=ext-gen65 class="x-menu-item-icon " alt="" src="https://servman/sm/js/extjs/resources/images/default/s.gif"><SPAN id=ext-gen66 class=x-menu-item-text>List View</SPAN></A></LI>

Open in new window


My attempt
For Each Btn In objFrameDoc.getElementsByTagType("LI")
            If btn.text= " List View" Then
                btn.Click

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
Hi,

pls try

Set ObjA = ie.Document.getElementByID("x-menu-el-ext-comp-6813").getElementsByTagName("A")(0)
  ObjA.Click 

Open in new window


Regards

Author

Commented:
I'm getting a run-time error '438'.  Object doesn't support this property or method.
Top Expert 2016

Commented:
Sorry cannot help further
Commented:
I found the solution

For Each Btn In objFrameDoc.getElementsByClassName("x-menu-item")
            If btn.ID= "ext-comp-6813" Then
            If Btn.href="https://servman/sm/cwc/cwc_listdetail.jsp:thread=25#" Then
                btn.Click

Open in new window

Author

Commented:
I found the solution on my own.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial