getElementbyID excell vba click on the link in a sidebar

kkoser

New Member
Joined
Mar 27, 2018
Messages
11
Hi folks.
I am at a loss here and am not sure what i am doing wrong.

Capture.JPG


i am trying to click on this link:

"Document Browser
"



isn't it as simple as... (this is what i started with)

Code:
Sub clickthebutton()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement


IE.Visible = True
IE.Navigate "https://cbase.lsgskychefs.com/main.aspx"


Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop


Set HTMLDoc = IE.Document
Set HTMLInput = HTMLDoc.getElementById("productionBrowser")
HTMLInput.Click


End Sub
<link rel="shortcut icon" href="/Images/Icons/cbase_logo.ico"><link rel="stylesheet" href="/Themes/LSG/defaults.min.css"><link rel="stylesheet" href="/Themes/LSG/checkboxes.min.css">
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi folks.
I am at a loss here and am not sure what i am doing wrong.

Capture.JPG


i am trying to click on this link:

"Document Browser
"



isn't it as simple as... (this is what i started with)

Code:
Sub clickthebutton()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement


IE.Visible = True
IE.Navigate "https://cbase.lsgskychefs.com/main.aspx"


Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop


Set HTMLDoc = IE.Document
Set HTMLInput = HTMLDoc.getElementById("productionBrowser")
HTMLInput.Click


End Sub
<link rel="shortcut icon" href="/Images/Icons/cbase_logo.ico"><link rel="stylesheet" href="/Themes/LSG/defaults.min.css"><link rel="stylesheet" href="/Themes/LSG/checkboxes.min.css">



oops.
edit:

Set HTMLInput = HTMLDoc.getElementById("documentBrowser")
 
Upvote 0
IvU1Q7P



this screenshot might help a little.

looks really simple however it is a link that is on a sidebar. .js might be involved too?

not much hair left on my head to pull out....
 
Upvote 0
Well, i had a bit of success. i was able to click on the link to make it load the page by using this.

Code:
Sub clickthebutton()
Dim IE As New SHDocVw.InternetExplorer
Dim Link As Object
Dim ElementCol As Object
Dim objIE As InternetExplorer




IE.Visible = True
IE.Navigate "https://cbase.lsgskychefs.com/main.aspx"


Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop


Application.Wait Now + TimeValue("00:00:05")


 Set ElementCol = IE.Document.getElementsByTagName("a")
    For Each Link In ElementCol
        Debug.Print Link.innerText
        If Link.innerText Like "Document Browser" Then
            Link.Click
            Exit For
        End If
    Next Link




End Sub

Now, i run into the same issue a noob like me can't figure out without a bit of help.

i am trying to input "1234" into this input. but i cannot navigate to it. Any suggestions? (Please see screenshot)

URL]


xmAZb12
 
Upvote 0
Maybe this:
Code:
Dim HTMLdoc As HTMLDocument
Dim textInput As HTMLInputElement
Set HTMLdoc = IE.document
Set textInput = HTMLdoc.getElementById("txtSearchFlight")
textInput.value = "1234"
You may need to input the text value character by character, sending the relevant event (via fireEvent or dispatchEvent) for each character.

Is it in an iframe? If so, you need to first assign the contentDocument of the iframe to HTMLdoc in the above code.
 
Upvote 0
[TABLE="width: 1136"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Thanks John for the reply.[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]yes, there is an iframe involved. looking up the html,[/TD]
[/TR]
[TR]
[TD]
HTML:
******** name="mainiframecontent" id="mainiframe" src="Pages/OP/DocumentBrowser.aspx" frameborder="0" style="opacity: 1;" allowtransparency="true">/iframe
[/TD]
[/TR]
[TR]
[TD]the html form is like this:[/TD]
[/TR]
[TR]
[TD]
HTML:
<form name="aspnetForm" id="aspnetForm" action="DocumentBrowser.aspx" enctype="multipart/form-data" method="post">
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
This is really tough for me.

Here is the (id) heirarchy.

html
body
form#form1​
div#sitecontainer​
div#pagecontainer​
div#loader-mask​
div#maincontainer​
div#iframecontent​
iframe#mainframe​
html
body​
form#aspnetForm​
div#tabs​
div#tabs-1​
div.toolbar​
div.toolbarinput​
input#txtSearchFlight '<-----trying to get here​

so frustrating when you are trying to learn how to do things better

any help navigating to this input would be greatly appreciated.

i have tried this and when debugged it only showed 1 form in the immediate window.

Code:
Sub clickthebutton()
Dim IE As New SHDocVw.InternetExplorer
Dim Link As Object
'Dim ElementCol As Object
Dim objitem As Object
Dim objIE As Object




IE.Visible = True
IE.Navigate "https://cbase.lsgskychefs.com/main.aspx"


Do While IE.READYSTATE <> READYSTATE_COMPLETE
Loop


Application.Wait Now + TimeValue("00:00:05")


 Set ElementCol = IE.Document.getElementsByTagName("a")
    For Each Link In ElementCol
       ' Debug.Print Link.innerText
        If Link.innerText Like "Document Browser" Then
            Link.Click
            Exit For
        End If
    Next Link


Application.Wait Now + TimeValue("00:00:05")
          
   
    With IE.Document


      Dim domIFrame As MSHTML.HTMLDocument
      Debug.Print IE.Document.forms.Length
      
      Set domIFrame = .frames("mainframecontent").Document


      With domIFrame
    
        .querySelector("*[id='txtSearchFlight']").Value = ThisWorkbook.Sheets("sheet1").Range("A1").Value


      End With
    End With
 
End Sub
 
Upvote 0
I cannot test because your URL presents a login page.

Maybe this:

Code:
    Dim HTMLdoc As HTMLDocument
    Dim textInput As HTMLInputElement
    
    'After logging in and page has completely loaded
    Set HTMLdoc = IE.document
    
    'Either
    Set HTMLdoc = HTMLdoc.getElementsByTagName("IFRAME")(0).contentDocument  'assumes 1st iframe
    
    'Or
    Set HTMLdoc = HTMLdoc.getElementById("mainiframe").contentDocument

    MsgBox HTMLdoc.body.innerHTML 'have we got correct document?
    
    Set textInput = HTMLdoc.getElementById("txtSearchFlight")
    
    MsgBox textInput.outerHTML  'have we got correct input element?
    
    textInput.Value = "1234"
 
Upvote 0
John,
That WORKED!

Also your comments are well understood to define the process to where i can navigate to it.

i hope others can use this thread to help out too.

Thank you very much.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top