Results 1 to 15 of 15

Thread: WebBrowser Click Button (JavaScript) [Resolved]

  1. #1

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Resolved WebBrowser Click Button (JavaScript) [Resolved]

    Hi Guys,

    This on is a little tricky.....

    I have an ADSL Moden that I want to be able to control (thru code) the Wireless function (Enable/Disable).

    Sounds easy enough, except there is NO elements that I can use!
    The HTML (containing JavaScript) dosn't alude to any "Button" Names or ID's.

    I first need to select the button to open a new controlbox (not window, as this stays the same URL) to get to the CheckBox that performs the Wireless control. I also cannot manipulate
    this checkbox even when I manualy navigate to this spot! - I get Object not set with .... dialog.
    I therefore asumed that the Webbrowser, for what ever reason, isn't holding those objects.

    In any case, first things first - I need to be able to .Click that first button

    I have exhausted my use/knowledge of DOM etc.



    Ideas?


    (PS I will upload the HTML latter)




    Cheers 'n' Beers,
    Bruce.
    Last edited by Bruce Fox; Apr 19th, 2005 at 06:55 PM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: WebBrowser Click Button (JavaScript)

    This might help, I found it earlier.

    http://msdn.microsoft.com/workshop/a...ence_entry.asp

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: WebBrowser Click Button (JavaScript)

    Also, this thread contains allot of good web page automation and parsing techniques.

    Data From Webpage


    Ps, sup Brucy Bruce
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: WebBrowser Click Button (JavaScript)

    Thanks David and Rob .

    I'm at home now and trying a few things



    Bruce.

  5. #5

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: WebBrowser Click Button (JavaScript)

    Ok, those methods were similar to what I was doing.
    (Also, for what it's worth, I had searched all day, and never came across that post!!)

    Anhoo,
    I still cant get passed the Run-Time Error '91' With Block Variable yada yada...


    However, I need to go back one step, and .Click one of those 'java' buttons.

    Attached is the HTML page (text view) and associated controlpanel.

    The button in question is "Wireless".

    As you can see there is no Button objects...

    (Please note I have two issues. 1. Clicking a button, and 2. in another controlset (display of buttons/checkboxs), clicking a CheckBox)

    I will say at this time that the CheckBox issue is ovevercome by generating errors on that page load????? If a browser error occurs, I can .Click the CheckBox after cycling the error prompts.... (caching?)




    Bruce.
    Last edited by Bruce Fox; Apr 19th, 2005 at 07:02 PM. Reason: Attachments Removed

  6. #6
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: WebBrowser Click Button (JavaScript)

    Well, for starters, just the HTML page doesn't do much without the JavaScript file that contains the code to generate the menu. Can you attach that one as well (../html/js/menu.js).

    As for the problem at hand, try viewing the HTML of the body at runtime, when the navigational buttons have been created (document.body.innerHTML). That code should include all generated content. You may be able to extract info of the buttons from there.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  7. #7

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: WebBrowser Click Button (JavaScript)

    Thanks for the reply Vader


    Ok, I have attached the JS file (as menu.txt(zip)), and the results of the innerHTML after the page had loaded as innerHTML.txt.

    Note: I have many times tried to navigate to the wireless.htm directly thru code, but that generates browser errors. I guess there are a few unset variables that are requried - hence the browser errors. Because of this I have tried to submit a .Click to the 'wirless' button.
    VB Code:
    1. WebBrowser1.Document.location.href = "../cgi-bin/webcm?getpage=../html/home/home_wizard.htm"




    innerHTML Results:
    <FRAME name=fPanel marginWidth=0 marginHeight=0 src=""><FRAME name=fInfo src="../cgi-bin/webcm?getpage=../html/home/home_RelaodHref.htm&amp;var:RelaodHref="><NOFRAMES>
    <body bgcolor="#008080">
    <p>This page uses frames, but your browser doesn't support them.</p>
    </body>
    </NOFRAMES>



    (PS I have clipped the tail end of the attached Java Code (menu.txt))

    Regards,
    Bruce
    Last edited by Bruce Fox; Apr 19th, 2005 at 07:05 PM.

  8. #8
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: WebBrowser Click Button (JavaScript)

    I don't understand much of the structure of that site... but it looks like the index page is a frameset that contains other pages. You can get to those pages with the document.frames collection.

    It would be much easier if I could just navigate to the page on the web; can you post the URL? I get script errors when I try to open mytext.htm with menu.js.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  9. #9

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: WebBrowser Click Button (JavaScript)

    Unfortunatly I cannot provide the URL, as its internal to my ADSL Modem.

    I will try to iterate Frame collection




    Bruce.

  10. #10
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: WebBrowser Click Button (JavaScript)

    Okay; this piece of code may help you. It adds all (inline) frames (including nested ones) to a collection colDocuments. You can use items from colDocuments just like any other document object (e.g. you can use colDocuments(0).body.innerHTML).
    VB Code:
    1. Private Sub GetFrames()
    2. 'Purpose: searches all frames in the document(s) and adds them to colDocuments
    3.  
    4. Dim i As Integer, j As Integer
    5. j = 1
    6.  
    7. Set colDocuments = New Collection
    8. colDocuments.Add WebBrowser1.Document
    9.  
    10. Do While j < colDocuments.Count + 1
    11.     For i = 0 To colDocuments.Item(j).frames.length - 1
    12.         colDocuments.Add colDocuments.Item(j).frames.Item(i).Document
    13.     Next i
    14.     j = j + 1
    15. Loop
    16. End Sub
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  11. #11

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: WebBrowser Click Button (JavaScript)

    Ok, thats what I needed. I now have the TD/TR matrix.

    I will try to iterate thru that and on match, perform a .Click (to envoke the "doLink('/html/home/wireless.htm')!





    Bruce.

  12. #12

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: WebBrowser Click Button (JavaScript)

    I have beena ble to load the Collection, iterate thru and determine the index/location of the TD containing the 'Wireless' tag.

    Now I have that, I cannot work out the syntax to be used on the WebBrowser.Document to perform a .Click on that item?

    VB Code:
    1. WebBrowser1.Document.All.Item(3).body.innerHTML.getElementsByName("TD").Item(8).Click




    Bruce.

  13. #13
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: WebBrowser Click Button (JavaScript)

    The syntax is fine, but you shouldn't use the WebBrowser1.Document object... just call the Click event from the colDocuments collection.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  14. #14

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: WebBrowser Click Button (JavaScript)

    Vadar, you Guru you!

    Thankyou for your persistance.

    Solution:
    VB Code:
    1. colDocuments(3).getElementsByName("TD").Item(10).Click



    All the best with you problem too


    Regards,
    Bruce.

  15. #15
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: WebBrowser Click Button (JavaScript)

    You're welcome. As for my problem: I've found a satisfying work-around; but it remains strange behavior...
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width