[英]C# Webbrowser fill in login page programmatically
I have a login form I wanna fill programmatically in C# I have a webbrowser and I did it this way, but it doesn't fill the form.我有一个登录表单,我想在 C# 中以编程方式填写我有一个网络浏览器,我是这样做的,但它没有填写表单。
<div>
<label class="control-label" for="Login">Login</label>
<input class="input-sm form-control" data-val="true" data-val-required="The Login field is required." id="Login" name="Login" type="text" value="">
</div>
<div>
<label class="control-label" for="Password">Password</label>
<input class="input-sm form-control" data-val="true" data-val-required="The Password field is required." id="Password" name="Password" type="password" value="">
</div>
<div>
<input type="submit" class="btn btn-default btn-sm" value="Valider" id="CmdValider">
<input type="button" class="btn btn-default btn-sm" value="Quitter" onclick="javascript:window.close();">
</div>
How I tried to fill them我是如何尝试填满它们的
webBrowser1.Document.GetElementById("Login").SetAttribute("Login", "myLogin");
webBrowser1.Document.GetElementById("Password").SetAttribute("Password", "myPassword");
I'm only able to click on the login button, which works but is useless until I find how to fill the login and password我只能点击登录按钮,该按钮有效但没用,直到我找到如何填写登录名和密码
webBrowser1.Document.GetElementById("CmdValider").InvokeMember("click");
Thanks for your help谢谢你的帮助
For both queries, you should be doing对于这两个查询,你应该做
webBrowser1.Document.GetElementById("elementid").SetAttribute("value", "something");
The only difference is that in SetAttribute
I'm passing the first argument as "value"
instead of something else.唯一的区别是,在SetAttribute
中,我将第一个参数作为"value"
而不是其他参数传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.