0

我正在尝试操作在 webbrowser 控件中打开的 html 表,此工具将用于访问带有自动登录选项的共享点页面。到目前为止,这就是我所拥有的:

HtmlElementCollection htmlcol = 
    wb.Document.GetElementsByTagName("formTextfield277");

for (int i = 0; i < htmlcol.Count; i++)
{
    if (htmlcol[i].Name == "portal_id")
    {
        htmlcol[i].SetAttribute("VALUE", 
                                Properties.Settings.Default.sharepoint_user);
    }
    else if (htmlcol[i].Name == "password")
    {
        htmlcol[i].SetAttribute("VALUE", 
                                Properties.Settings.Default.sharepoint_pw);
    }
}

此 C# 代码用于操作此 HTML 页面:

<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%" BORDER="0">
    <TR>
        <TD CLASS="txtRedBold10" WIDTH="4">&nbsp;</TD>
        <TD CLASS="txtRedBold10" COLSPAN="2" HEIGHT="30">Please log in</TD>
    </TR>
    <TR>
        <TD CLASS="txtBlackReg10" WIDTH="4">&nbsp;</TD>
        <TD CLASS="txtBlackReg10">Username:</TD>
        <TD><INPUT CLASS="formTextfield277" TYPE="text" NAME="portal_id" VALUE=""  VCARD_NAME="vCard.Email" SIZE="28"></TD>
    </TR>
    <TR>
        <TD CLASS="txtBlackReg10" COLSPAN="3">&nbsp;</TD>
    </TR>
    <TR>
        <TD CLASS="txtBlackReg10" COLSPAN="2">&nbsp;</TD>
        <TD CLASS="txtBlackReg10">Please enter your username or E-Mail Address</TD>
    </TR>
    <TR>
        <TD CLASS="txtBlackReg10" COLSPAN="3">&nbsp;</TD>
    </TR>
    <TR>
        <TD CLASS="txtBlackReg10" WIDTH="4">&nbsp;</TD>
        <TD CLASS="txtBlackReg10">Password:</TD>
        <TD><INPUT CLASS="formTextfield277" TYPE="password" NAME="password" SIZE="28" AUTOCOMPLETE="off"></TD>
    </TR>
    <TR>
        <TD CLASS="txtBlackReg10" COLSPAN="3">&nbsp;</TD>
    </TR>
    <TR>
        <TD CLASS="txtBlackReg10" COLSPAN="2">&nbsp;</TD>
        <TD CLASS="txtBlackReg10">Please enter your network or Intranet password</TD>
    </TR>
    <TR>
        <TD CLASS="txtBlackReg10" COLSPAN="3">&nbsp;</TD>
    </TR>

    <TR>
        <TD CLASS="txtBlackReg10" COLSPAN="2">&nbsp;</TD>
        <TD CLASS="txtBlackReg10">
            <TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
                <TR>
                    <TD><INPUT TYPE="image" HEIGHT="24" WIDTH="20" SRC="images/cp_arrow.gif" VALUE="Log In"
                               BORDER="0"></TD>
                    <TD><A CLASS="linkTxtRedBold10" HREF="javascript:signin()"
                           onClick="saveForm()">Login</A>
                    </TD>
                </TR>
            </TABLE>
        </TD>
    </TR>
    <TR>
        <TD CLASS="txtBlackReg10" COLSPAN="3">&nbsp;</TD>
    </TR>
</TABLE>

有什么建议吗?

提前致谢!

4

1 回答 1

1

wb.Document.GetElementsByTagName("input") 不是 wb.Document.GetElementsByTagName("formTextfield277");

 HtmlElementCollection inputHtmlCollection = Document.GetElementsByTagName("input");
 foreach (HtmlElement anInputElement in inputHtmlCollection)
{
                    if (anInputElement.Name.Equals("portal_id"))
                    {
                        anInputElement.SetAttribute("VALUE", Properties.Settings.Default.sharepoint_user);
                    }
                    if (anInputElement.Name.Equals("password"))
                    {
                        anInputElement.SetAttribute("VALUE",  roperties.Settings.Default.sharepoint_pw);
                    }
}

希望这有帮助!

于 2013-09-26T02:38:46.823 回答