C# 如何通过浏览器自动点击按钮
我的点击页面的 Html 代码是:
<input type="submit" id="publishButton-ns" class="ubtn ubtn-block"
name="publish" tabindex="10" value="Publish Post">
我尝试使用此代码进行点击:
webBrowser1.Document.GetElementById("publishButton-ns").InvokeMember("click");
但这没有找到按钮。
The Html code of my click page is :
<input type="submit" id="publishButton-ns" class="ubtn ubtn-block"
name="publish" tabindex="10" value="Publish Post">
I tried this code for clicking:
webBrowser1.Document.GetElementById("publishButton-ns").InvokeMember("click");
but this not found the button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这可能对你有帮助。
This may help you.
您是否正在等待页面加载?您应该在代码中绑定一个函数来等待页面加载,然后单击按钮:
Are you waiting for the page to load first? You should bind a function in your code to wait for the page to load, them click the button:
尝试结合 @adam 的建议并大写
Click
刚刚测试了这一点,它不适用于“click”,但适用于“Click”:)
我正在使用 .net 4
Try a combination of @adam's suggestion and capitalize
Click
Just tested this and it didn't work with "click" but did with "Click" :)
I'm using .net 4
编辑:这只适用于设置
runat="server"
的情况,在这种情况下不适用,但为了以防万一,我很抱歉在问题中遗漏了这一点。ASP.Net 根据元素所在的结构更改其呈现的元素名称,您可以尝试以下操作来获取元素的最终名称:
EDIT: This only applies when
runat="server"
is set, not applicable in this case but leaving for others just in case, my apologies on missing that in the question.ASP.Net changes the name of elements it renders based on the structure they are in, you can try the following to get the final name of the element:
您可以使用 jQuery,然后执行类似 $("#publishButton-ns").click(); 的操作
http://www.jQuery.com/
You can use jQuery and then do something like this $("#publishButton-ns").click();
http://www.jQuery.com/