code-gijoe
code-gijoe

Reputation: 7234

How to click a button in web page using VB?

I'm creating a VB script that clicks a button on a webpage. I've seen answers such as this where they submit the form. I don't want this since I require to click on the button with a script so that the usual workflow of clicking a button is engaged.

By the way I'm using GWT and SmartClient which makes it a bit more complex as ID's get obfuscated. To overcome this I'm using GWT DEBUG_ID_PREFIX

Upvotes: 0

Views: 3301

Answers (1)

Kul-Tigin
Kul-Tigin

Reputation: 16950

Would be nice if you gave a sample of a GWT button to getting help from for those who does not familiar with GWT like me. I found a page that contains a GWT button (hope) and wrote something based on that.
Consider the following code.

Sub WaitUntil(varObj)
    On Error Resume Next
    Do
        WScript.Sleep 100
    Loop Until Not varObj Is Nothing
    WScript.Sleep 500
End Sub

Dim IE
Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate "http://gwt.google.com/samples/Showcase/Showcase.html#!CwBasicButton"
    WScript.Sleep 500
    WaitUntil IE.Document 'wait until the document is ready
    WaitUntil IE.Document.getElementById("gwt-debug-cwBasicButton-normal") 'wait until the button is initialized
    Dim theButton
    Set theButton = IE.Document.getElementById("gwt-debug-cwBasicButton-normal")
        theButton.Click
        'theButton.fireEvent "onclick" 'another way
Set IE = Nothing

Upvotes: 1

Related Questions