gpt4 book ai didi

asp.net - 如何以编程方式单击 ASP.NET 网页上的按钮?

转载 作者:行者123 更新时间:2023-12-04 09:34:09 27 4
gpt4 key购买 nike

我想弄清楚如何以编程方式单击网页上的按钮。

具体来说,我有一个带有 WebBrowser 控件的 WinForm。一旦它导航到我尝试使用的目标 ASP.NET 登录页面,在 DocumentCompleted 事件处理程序中,我有以下编码:

HtmlDocument doc = webBrowser1.Document;

HtmlElement userID = doc.GetElementById("userIDTextBox");
userID.InnerText = "user1";

HtmlElement password = doc.GetElementById("userPasswordTextBox");
password.InnerText = "password";

HtmlElement button = doc.GetElementById("logonButton");
button.RaiseEvent("onclick");

这很好地填充了用户 ID 和密码文本框,但我没有成功点击那个该死的按钮;我也试过“点击”、“点击”和“点击”——还有什么?对 msdn 的搜索当然没有给我任何线索,groups.google.com 也没有。我得靠近。或者也许不是——有人告诉我我应该调用页面的 POST 方法,但是如何做到这一点并不是给出的建议的一部分。

BTW 按钮编码:
<input type="submit" name="logonButton" value="Login" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="logonButton" tabindex="4" />

最佳答案

这是如何运作的?为我工作

HtmlDocument doc = webBrowser1.Document;

doc.All["userIDTextBox"].SetAttribute("Value", "user1");
doc.All["userPasswordTextBox"].SetAttribute("Value", "Password!");
doc.All["logonButton"].InvokeMember("Click");

关于asp.net - 如何以编程方式单击 ASP.NET 网页上的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/96153/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com