0

I'm not too familiar with getting the elements from IE, but I've been successful when it's straight-forward. The website I'm working with now is confusing me.

I am launching a site and putting in the username & password, then I want to click the login button but I am failing to find the correct way to locate and click the button since it doesn't have an ID.

I have seen various posts on this site with similar questions and I have tried following the advice in those posts but still can't get it to work.

I will share my code and the element information from the site.

Dim IEapp As InternetExplorerMedium
Dim divClassLogin As Object
Set IEapp = New InternetExplorerMedium

    With IEapp
        .Navigate "http://ctdayppv02/PVE.aspx"
        .Visible = True
        .AddressBar = 0
        .StatusBar = 0
        .Toolbar = 0
        .MenuBar = 0
        .Height = 700
        .Width = 950
    End With

    Do While IEapp.Busy: DoEvents: Loop
    Do Until IEapp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

    IEapp.Document.all.Item("txtUserName").Value = "Name"
    IEapp.Document.all.Item("txtPassword").Value = "Pass"
    IEapp.Document.all.Item("btnLogin").Click

This is the IE Inspect Elements html.

IE HTML

This is the Chrome Inspect Elements html.

Chrome HTML

The posts I've referenced on this site are (amongst others):

Click button on login page

VBA to click on a button in IE with no ID, Name, ClassName

Use VBA to click on a button in IE

Can somebody help me identify what element I should be looking at to click login? I'm used to finding an ID or something that says "Submit" but I'm not seeing it on this site.

Thanks in advance.

TBoulz
  • 339
  • 5
  • 20
  • I don't see a button in that html either and the url does not seem to be accessible, publicly at least. Is that the actual URL in your post? In any case right click on the webpage in Firefox or Chrome & chose Inspect Element, then update your post with that html – Absinthe Jul 26 '18 at 18:07
  • @Absinthe thanks for taking a look. First, that is the actual URL that is in my code. Not sure if you have access to it outside of our company intranet. Second, I updated my post to include what Chrome shows. – TBoulz Jul 26 '18 at 18:38
  • The element at the highlighted at top maybe selectable via ieApp.document.querySelector("span[widgetId=btnLogin]").Click – QHarr Jul 26 '18 at 19:03
  • @QHarr thank you for the feedback. I tried both `ieApp.document.querySelector("span[widgetId=btnLogin]").Click` and `IEAPP.document.querySelector("input[name=btnLogin]").Click` and get the same error...`Object doesn't support this property or method`, so perhaps there is something I am missing and then those would work? – TBoulz Jul 26 '18 at 19:09
  • Also, sorry for the images. I have not used the snippet tool before and was unaware of it's existance. – TBoulz Jul 26 '18 at 19:10
  • What version of IE are you using? And if you press F12 and look at the emulation tab ewhat is the document mode? Snippet is Ctrl + M with your HTML highlighted in the question. It's the icon that looks like a file with angle brackets on it. – QHarr Jul 26 '18 at 19:10
  • @QHarrI am using IE 11, and the Document mode is 8 (default). Should the document mode match my version of IE? – TBoulz Jul 26 '18 at 19:21
  • Can you change it to Edge/latest version? I guess also is there anything in the code that sets the emulation mode. But try setting to Edge first and then running. – QHarr Jul 26 '18 at 20:00
  • @TBoulz I also can't access the URL too. One more thing i found that in your IE screenshot it seems like the html code not expand to the end. Supposedly, it will have black arrow such as in the line `
    `. Can you please update this?
    – user2851376 Jul 27 '18 at 05:48
  • Did any of these work? – QHarr Jul 27 '18 at 11:29
  • Hi, sorry I just signed back on now. I updated the post to include the expanded IE HTML like @user2851376 requested. I'm not surprised that nobody can access the URL, I think you would need to be on our company intranet in order to access it. I've had some success with the below answer. I will comment on it. – TBoulz Jul 27 '18 at 11:41

1 Answers1

1

As I cannot access the URL. I just come out with the code (without testing it) that I usually do and for me the most flexible way even though it quite long. Please try:

Dim ee as Variant, htmldoc
Set htmldoc= IEapp.document
For each ee in htmldoc.getElementsByTagName("span")
   If ee.className = "dijitReset dijitInline dijitButtonNode" And InStr(ee.innerHTML, "btnLogin") > 0 Then 'not sure whether innerhtml or outerhtml you need tp check in your watches
      ee.Click: DoEvents: Sleep 1000
      ''or u can try this
      ee.FireEvent ("onclick"): DoEvents: Sleep 1000
      Exit For
    End If
 Next ee
user2851376
  • 173
  • 3
  • 11
  • This did work after I declared `Sleep` for 64-Bit. Strangely, this logs me into the site but doesn't load the main form that would usually appear if I signed in manually. However, the sidebar navigation is still there and accessible so I will look to click on the appropriate link in the sidebar and go from there. Marking this as accepted because it got me logged in one way or another and that was my question. Thank you very much for this! – TBoulz Jul 27 '18 at 11:45
  • Glad to know it helps your problems! You are most welcome. Regarding it point to other page, I can't explain much on this because it depends on the website itself to interact – user2851376 Jul 27 '18 at 13:59
  • In fact, it seems to be loading the proper form now. I guess it was a temporary issue with the webpage. Either way, I will always choose the proper form from the sidebar to ensure I am at the correct location. Thanks again. – TBoulz Jul 27 '18 at 15:10