Results 1 to 3 of 3

Thread: WebBrowser1 Control Auto Click Button

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    24

    WebBrowser1 Control Auto Click Button

    HI,

    In Vb6 WebBrowser1 Control i am trying to click a button automatically

    However the button does not have a "button name" just a label of "Edit"

    now there are 2 of these forms/buttons on the same page

    if i do the following command it clicks form2 "Edit" and misses form1 "Edit"
    so it goes to page 2 rather than clicking the first "Edit" for page1.

    here is the code i am using and the code below is of the 2 forms

    For X = 0 To WebBrowser1.Document.Forms.length - 1

    For i = 0 To WebBrowser1.Document.Forms(X).length - 1

    If WebBrowser1.Document.Forms(X)(i).Value = "Edit" Then
    WebBrowser1.Document.Forms(X)(i).Click
    End If

    Next i

    Next X



    1st form

    <form action='/accounts/' method='post' id='server_form_9d32bebd_2a94_4dad_9ae8_01b8e7022814' name='server_form_9d32bebd_2a94_4dad_9ae8_01b8e7022814' onsubmit='x=server_form_9d32bebd_2a94_4dad_9ae8_01b8e7022814; x.delete_server.disabled=true; x.start_server.disabled=true;'>
    <input type='hidden' id='uuid' name='uuid' value='9d32bebd-2a94-4dad-9ae8-01b8e7022814'/>
    <input type='hidden' id='form' name='form' value='stopped_server'/>
    <input type='hidden' value='' id='start_server_check' name='start_server_check'/>
    <input type='hidden' value='' id='delete_server_check' name='delete_server_check'/>
    <input type='submit' id='start_server' name='start_server' value='Start' onclick='x=server_form_9d32bebd_2a94_4dad_9ae8_01b8e7022814; x.start_server_check.value="start_server"; x.start_server.value="Processing...";'/>
    <input type='button' value='Edit' onclick='location.href="/accounts/config/9d32bebd-2a94-4dad-9ae8-01b8e7022814"'/>
    <input type='submit' id='delete_server' name='delete_server' value='Delete' onclick='if (confirm("Are you sure that you want to permanently delete this server?")) { x=server_form_9d32bebd_2a94_4dad_9ae8_01b8e7022814; x.delete_server_check.value="delete_server"; x.delete_server.value="Processing..."; return true; } else { return false; }'/>
    </form>







    2nd form

    <form action='/accounts/' method='post' id='drive_destroy_form_64148a89_a782_4335_b62a_9dad3b857705' name='drive_destroy_form_64148a89_a782_4335_b62a_9dad3b857705' onsubmit='x=drive_destroy_form_64148a89_a782_4335_b62a_9dad3b857705; x.delete_drive.disabled=true; x.copy_drive.disabled=true;'>
    <input type='hidden' id='uuid' name='uuid' value='64148a89-a782-4335-b62a-9dad3b857705'/>
    <input type='hidden' id='form' name='form' value='drive_action'/>
    <input type='button' value='Edit' onclick='location.href="/accounts/drive/64148a89-a782-4335-b62a-9dad3b857705"'/>
    <input type='hidden' value='' id='copy_drive_check' name='copy_drive_check'/>
    <input type='hidden' value='' id='delete_drive_check' name='delete_drive_check'/>

    <input type='submit' value='Copy' id='copy_drive' name='copy_drive' onclick='x=drive_destroy_form_64148a89_a782_4335_b62a_9dad3b857705; x.copy_drive_check.value="copy_drive"; x.copy_drive.value="Processing...";'/>


    <input type='submit' value='Delete' id='delete_drive' name='delete_drive' onclick='if (confirm("Are you sure that you want to permanently delete this drive and all data stored on it?")) { x=drive_destroy_form_64148a89_a782_4335_b62a_9dad3b857705; x.delete_drive_check.value="delete_drive"; x.delete_drive.value="Processing..."; return true; } else { return false; }'/>

    </form>

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: WebBrowser1 Control Auto Click Button

    I suspect you're clicking on both but the second 'click' is overriding the first. If you know it's the button on the first Form why not just process that Form?
    Code:
    For i = 0 To WebBrowser1.Document.Forms(0).length - 1
        If WebBrowser1.Document.Forms(0)(i).Value = "Edit" Then
            WebBrowser1.Document.Forms(0)(i).Click
        End If
    Next i
    and remove the 'X' loop.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    24

    Re: WebBrowser1 Control Auto Click Button

    hi , I tried the above code
    but still not working

    how can i manually find out the numbers for each element

    what would be the code to display in msg box or something
    all the element numbers

    thanks

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