首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getElementByID搜索

getElementByID搜索
EN

Stack Overflow用户
提问于 2013-12-25 09:49:15
回答 2查看 1.2K关注 0票数 0

我的问题是在代码的下一部分之前在网页上搜索一个名为“输入ID”类型的元素。下面的代码找不到这个元素,只是不停地循环。

代码语言:javascript
复制
Dim Elem As Object

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

' Next part of code.

谢谢..

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-31 13:06:05

试试这段代码

代码语言:javascript
复制
  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
票数 1
EN

Stack Overflow用户

发布于 2013-12-30 07:28:09

好吧,我还是把这个发出去。我认为在VBA中重构这一点并不难,如果您看到了逻辑:

代码语言:javascript
复制
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);
}

然后你就这样在你的页面里这样称呼它:

代码语言:javascript
复制
Control MyControl = new Control();
MyFoundControl = FindControl(this, "MyControlName");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20771388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档