PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Webbrowser & button click-VBForums
Results 1 to 9 of 9

Thread: Webbrowser & button click

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Question Webbrowser & button click

    Hi,

    I have created a webbrowser and am able to visit various sites.

    While I browse some site, I want to click on some button at regular intervals. How can I do this ?

    Any ideas would be appreciated.

    Thank You,

    Harish
    Last edited by harishys; Sep 10th, 2009 at 01:00 PM. Reason: Adding more information

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Re: Webbrowser & button click

    The webpage HTML contains the following section of code...

    Code:
    <br>
    	<div id="auctBidButtonON"><img src="images/bid_idle.png" alt=""
    	id="bidbut" width="83" height="33" border="0"
    	onmouseover="TrackBidButton(1)" onmouseout="TrackBidButton(0)"
    	onmousedown="TrackBidButton(2)" onmouseup="TrackBidButton(3)"
    	onclick="ClickBidButton(76,110728)">
    </div>
    I want to click this button from the VB code. I tried the following option;

    vb Code:
    1. WebBrowser1.Document.getElementByID("bidbut").Item(0).Click
    2.                         WebBrowser1.Document.getElementByID("auctBidButtonON").innerHTML.Click

    Both these options didnt work. I am clueless as to why this doesnt happen. However one thing what I noticed, is that there is anothe webpage where the button exits as part of the table code. There I am able to click it. But when button is enclosed in a <div> tag, the click does not go through.

    How can I go about doing this ?

    Best Regards,
    harish

  3. #3
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: Webbrowser & button click

    getElementByID does not return a collection of elements but rather a single element.

    Try removing .Item(0) from your first example.

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Thumbs down Re: Webbrowser & button click

    No... this does not work.
    Another thing that I noticed is, whenever DIVs are used "getElementByID" is not successful. This is true in the code that I mentioned earlier or even in the simple code mentioned below.

    HTML Code:
    <div id="timer_3174" class="countdown" title="1252947630">--:--:--</div>
    So I am wondering whether I can use some alternative to "getElementByID" so that it works for the HTML code with DIVs.

    Best Regards,
    Harish

  5. #5
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Webbrowser & button click

    Wow, these types of questions have been popping up alot lately. Check out my code here for an idea of enumerating elements:
    http://www.vbforums.com/showthread.php?t=584019 [POST #2]
    With a button element, you can click it via the click function, so:
    vb Code:
    1. Call oBtnEle.click()

    Also, could you post more source code, that is the parent element of that DIV.

    Quote Originally Posted by harishys
    However one thing what I noticed, is that there is anothe webpage where the button exits as part of the table code. There I am able to click it.
    Another Frame, doesn't the HTMLDocument have a Frames collection?

    EDIT: Yes it does. WebBrowser1.Document.frames
    Last edited by Xiphias3; Sep 14th, 2009 at 10:24 AM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Re: Webbrowser & button click

    Thanks a lot for the help... I will try this out...
    However, I have not been able to find any such help material neither online nor through books. Are you aware of some website / book to get more information about handling OLE and more so wrt webbrowsers ?

    This will be of great help..

    Best Regards,
    Harish

  7. #7
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Webbrowser & button click

    Quote Originally Posted by harishys
    However, I have not been able to find any such help material neither online nor through books. Are you aware of some website / book to get more information about handling OLE and more so wrt webbrowsers ?
    The reason [I figure] for this is that majority of what you need to know is in the HTML Object library and on MSDN, which is pretty straight forward with it's Element and Element Collection style, like what you saw on the page I linked you to. Reference this library via:

    Code:
    Project -> References -> Microsoft HTML Object Library
    However, if you dont know the bare basics of Object Oriented Programming (OOP), you probably won't get the "jist" of things. For Each was designed primarily for Object use, hence it's easier to use because the object you're using will be initialized, so you don't need to use a basic For (which is for primitives - Integer, Byte,etc), and include code like this:
    vb Code:
    1. Set object = Collection.Item(Index)
    2. 'Ub3r 1337 code...
    3. Set object = Nothing

    In OOP, it's all a hierarchy. For example,
    Code:
    HTMLElement
      |-HTMLInputElement
        |-HTMLTextInputElement
    So, if you have a Textbox element (with tagname INPUT) on a webpage (oEle), both of these conditions are true.

    vb Code:
    1. (TypeOf oEle Is HTMLInputElement)
    2. (TypeOf oEle Is HTMLTextElement)

    Anyway, as long as you reference the HTML lib, you're mostly good-2-go with help from intellisense, so declare your variables properly. When grabbing the HTML Document from the WebBrowser,

    Don't do this:
    vb Code:
    1. Dim doc as Object
    2. Set doc = WebBrowser1.Document

    And don't do this:
    vb Code:
    1. Dim doc as Variant
    2. Set doc = WebBrowser1.Document

    Do this:
    vb Code:
    1. Set oHTMLDoc as HTMLDocument
    2. Set oHTMLDoc = WebBrowser1.Document

    However, don't bet your life on it. Because of updates to the library over time, other class names have been introduced and so you cant always have all your eggs (functions,props,etc) in one basket (datatype). For example, here's a personal experience.

    I wanted to select and copy an image on a page to the Clipboard. The HTMLDocument returns IHTMLBodyElement for the body, which doesnt have the function createControlRange(), it's the HTMLBody that has that function. Point is, consult the Object Browser.

    Hope you understand what i'm saying. Reference the HTML Library, use the Object Browser's find functionality, debug the code and check the Locals/Watches window for info on datatypes and search MSDN. Dong that, you should be fine.

    EDIT: Try to enum Frames like this:
    vb Code:
    1. Dim oFrame as HTMLFrame, oHTMLDoc as HTMLDocument
    2.  
    3. Set oHTMLDoc = WebBrowser1.Document
    4. For Each oFrame In oHTMLDoc.frames
    5.     Debug.Print "Title: " & oFrame.title
    6. Next oFrame
    Last edited by Xiphias3; Sep 14th, 2009 at 01:00 PM.

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Re: Webbrowser & button click

    Hi,

    Thanks for such a nice explanation...

    I am currently using VB 6. Looks like it doesnt support HTMLelement, HTMLForm or the likes. I may have to move to the higher version... is that right ?

    Best Regards,
    harish

  9. #9
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Webbrowser & button click

    This is the VB6 forums, so I'm using VB6 too.
    Try the following:

    Project -> References -> Browse -> "System32\mshtml.tlb" -> Open

    You should see "Microsoft HTML Object Library" selected and checked. If not, lemme know.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width