0

enter image description hereI am a newbie trying to automate some routine procedures through Excel vba. But I can't access the HTML element that I want to click.I would like to click on the menu titled "Prize Bonds" and then would like to click to one of the submenus it opens up. I have tried to access it by tag, tagname, css, but nothing works. The error is not due to finding the element. I use wait to load the site so that the presence of element is not an issue.My code doesn't give any error but it also won't click on the menus stated. I am uploading the images to show DOM and finding the HTML element. The code is

Sub auto_ie()

 

 

Dim IE As New SHDocVw.InternetExplorer

Dim usrname As Variant

Dim pass As Variant

Dim MSDOC As MSHTML.HTMLDocument

Dim inputs As MSHTML.IHTMLElement

Dim passwords As MSHTML.IHTMLElement

Dim singin As MSHTML.IHTMLElement

Dim Anchors As MSHTML.IHTMLElementCollection

Dim anchor As MSHTML.IHTMLElement

 [[enter image description here](https://i.stack.imgur.com/g7cft.png)](https://i.stack.imgur.com/Ycog8.png)

usrname = ""

pass = ""

 

IE.Visible = True

IE.navigate ("")

 

Do While IE.readyState <> READYSTATE_COMPLETE

Loop

 

Set MSDOC = IE.document

Set inputs = MSDOC.getElementById("signOnName")

inputs.Value = usrname

 

Set inputs = MSDOC.getElementById("password")

inputs.Value = pass

 

Set singin = MSDOC.getElementById("sign-in")

singin.Click

 

 

Do While IE.readyState <> READYSTATE_COMPLETE

 

Loop

 

Do Until IE.readyState = 4

DoEvents

Loop

 

Set Anchor = MSDOC.getElementsByTagName("img")

For Each anchor In Anchors
     if anchor.innertext = "Prize Bonds" then
      anchor.click()
      End if
      Exit for

   Next anchor

    

     

     
End Sub

I have already described that I used different methods to get to the right HTML element and click it but they won't work

Jack Jan
  • 1
  • 1
  • IE is deprecated, many websites do not support IE anymore. If you can download 3rd party applications, suggest you look at [SeleniumBasic](https://florentbr.github.io/SeleniumBasic/) ... related [SO link](https://stackoverflow.com/q/67191954/11318818) and [SO link](https://stackoverflow.com/q/69118936/11318818) – JohnM Jul 05 '23 at 06:25
  • I know that but unfortunately my organization does not allow anyother third party applications due to security concerns. Otherwise, I think, my issue would have been solved by Selenium. – Jack Jan Jul 05 '23 at 09:42
  • You could try the WinAPI solution from this [SO answer](https://stackoverflow.com/a/72168314/11318818) – JohnM Jul 05 '23 at 11:16
  • Let me see if WinAPI works for me. – Jack Jan Jul 06 '23 at 09:03

0 Answers0