首页 > 解决方案 > 无法指示密码字段的 html id 并且无法使用 Win Forms 登录页面

问题描述

在此处输入图像描述尝试使用 WinForms 和 C# 登录到 Intranet 站点。

以下是登录代码 -

webbrowserObject.Document.GetElementById("USER").SetAttribute("value", Properties.Settings.Default.UserEmail);
webbrowserObject.Document.GetType("password").SetAttribute("Value", Properties.Settings.Default.UserPassword);
webbrowserObject.Document.GetElementById("loginbtn").InvokeMember("submit");

出现以下错误 -

Severity    Code    Description Project Path    File    Line    Suppression State
Error   CS1501  No overload for method 'GetType' takes 1 arguments

当我如下更改代码时 -

 webbrowserObject.Document.GetElementById("USER").SetAttribute("value", Properties.Settings.Default.UserEmail);
 webbrowserObject.Document.GetElementById("PASSWORD").SetAttribute("Value", Properties.Settings.Default.UserPassword);
 webbrowserObject.Document.GetElementById("loginbtn").InvokeMember("submit");
 while (!DocumentLoaded)

以下是错误 -

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

以下是我尝试登录的网站的 html 信息 -

<input name="USER" class="form-control textbox center-block noborder " id="USER" autofocus="" required="" type="text" placeholder="User ID">
<input name="PASSWORD" class="form-control textbox  center-block noborder" required="" onkeydown="return FormKeyPressed();" type="password" placeholder="Password">

标签: c#winforms

解决方案


推荐阅读