简体   繁体   English

从c#WPF代码自动登录到Web浏览器

[英]Auto Login to a WEB Browser from c# WPF code

I am trying to login to the site https://kite.zerodha.com/ from a Webbrowser control in my C# WPF application. 我正在尝试从C#WPF应用程序中的Webbrowser控件登录到站点https://kite.zerodha.com/ I am stuck because of the way the source code of the site is written as for none of the Input / Action elements there is any ID/TAG/NAME by which I can get the element and pass my input from my program. 我之所以陷入困境,是因为网站的源代码编写方式不像Input / Action元素那样,没有任何ID / TAG / NAME,通过它们我可以获取该元素并从程序中传递我的输入。

The source code of the site for the password field looks something like below : 该网站的密码字段的源代码如下所示:

<input type="password" maxlength="30" placeholder="" autocorrect="off" animate="true" label="" rules="[object Object]" dynamicwidthsize="8" autocomplete="off">

In my C# code on Loadcompletion of the browser I have got the HTML document as below: 在浏览器的Loadcompletion的C#代码中,我得到了如下的HTML文档:

htmldoc = LogInBrowser.Document as mshtml.HTMLDocument;

But now I am not able to proceed as to how can I access the password field and pass my input from my program. 但是现在我无法继续如何访问密码字段并从程序传递输入。

Some guidance would be of great help! 一些指导会很有帮助!

Thanks, Nandy 谢谢,南迪

You can achieve this by small trick. 您可以通过一些小技巧来实现。 Pass your password in the OuterHtml of HTML element. 在HTML元素的OuterHtml中传递密码。 Add the value element in the OuterHtml value=\\"Your_Password\\" 将value元素添加到OuterHtml value = \\“ Your_Password \\”中

// Get password element
HtmlElement passwordElement = (from HtmlElement element in webBrowser1.Document.GetElementsByTagName("input") select element)
    .Where(x => x.GetAttribute("type") == "password").FirstOrDefault();

if (passwordElement != null)
{
    passwordElement.OuterHtml = "<input type=\"password\" maxlength=\"30\" placeholder=\"Password\" autocorrect=\"off\" animate=\"true\" label=\"\" rules=\"[object Object]\" dynamicWidthSize=\"8\" autocomplete=\"off\" value=\"Your_Password\">";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM