user2952447
user2952447

Reputation: 139

getElementByID search

My question concerns searching for an element, titled, an 'input ID' type of element, on a webpage before next part of the code. My code, below, doesn't find the element and just keeps looping.

Dim Elem As Object

Do
    Set Elem = Nothing
    Set Elem = document.all.getElementById("XXXXXX")
    DoEvents
Loop While Elem Is Nothing

' Next part of code.

Thanks..

Upvotes: 0

Views: 1215

Answers (2)

Santosh
Santosh

Reputation: 12353

Try this code

  Sub Login()

    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")

    IE.Visible = True
    IE.navigate "https://appworld.blackberry.com/isvportal/home.do"


    Do While IE.readystate <> 4
        DoEvents
    Loop

    WaitFor 5

    Dim signInButton As Object
    Set signInButton = IE.document.getelementbyid("ssoLoginFrm_0")
    signInButton.Click

End Sub

Sub WaitFor(NumOfSeconds As Long)
    Dim SngSec As Long
    SngSec = Timer + NumOfSeconds

    Do While Timer < SngSec
        DoEvents
    Loop

End Sub

Upvotes: 1

ttaaoossuu
ttaaoossuu

Reputation: 7884

Okay, I will post this anyway. I think it wouldn't be hard to refactor this in VBA if you see the logic:

public static Control FindAnyControl(this Page page, string controlId)
{
    return FindControlRecursive(page.Form, controlId);
}

public static Control FindAnyControl(this UserControl control, string controlId)
{
    return FindControlRecursive(control, controlId);
}

public static Control FindControlRecursive(Control parent, string controlId)
{
    foreach (Control control in parent.Controls)
    {
        Control result = FindControlRecursive(control, controlId);
        if (result != null)
            return result;
    }
    return parent.FindControl(controlId);
}

Then you just call it like this in your page:

Control MyControl = new Control();
MyFoundControl = FindControl(this, "MyControlName");

Upvotes: 0

Related Questions