我可以为 WebBrowser 控件内部的输入设置值吗?
我有一个网页加载到 WebBrowser 对象中。我想要做的是访问该页面上的元素以输入数据。例如,输入用户名和密码并提交表单。
这怎么可能?有什么想法吗?
我可以使用 HTMLAgilityPack 访问元素并设置它们的值吗?
I have a web page loaded into a WebBrowser object. What I want to do is access the elements on that page to input data. For example, enter username and password and submit the form.
How is this possible? Any ideas?
Could I use HTMLAgilityPack to access the elements and set their values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看此文档示例:http://msdn。 microsoft.com/en-us/library/system.windows.forms.htmldocument.aspx
通过 Web 浏览器控件,有一个 HtmlDocument 类型的 Document 属性,它使您能够影响页面。我个人不知道它是否可以做你想做的一切,但这将是一个很好的起点。
HTH。
Check out this documentation example: http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument.aspx
Through the web browser control, there is a Document property of type HtmlDocument, which gives you some ability to affect the page. I personally don't know if it can do everything you want, but this would be a good starting point.
HTH.
有很多解决方案。我自己使用过的两个是:
WaitN - http://watin.sourceforge.net/
WebAii - 显然是由 Telerik 购买的?曾经有一个免费版本,不确定是否还有 - http://www.artoftest。 com/index.html
然后就是对 WebBrowser 控件使用自动化。自动化框架使其变得更加简单。
There are lots of solutions. Two that I've used myself are:
WaitN - http://watin.sourceforge.net/
WebAii - apparently purchased by Telerik? There used to be a free version, not sure if there is any longer - http://www.artoftest.com/index.html
Then there's just using automation against the WebBrowser control. An automation framework makes it so much simpler.
另请查看此示例,该示例使用 HtmlAgilityPack 使用用户名和密码字段执行 POST 请求:
http://refactoringaspnet.blogspot.com/2010/04/using-htmlagilitypack-to-get-and-post.html
Also check out this example which is using HtmlAgilityPack to do a POST request with username and password fields:
http://refactoringaspnet.blogspot.com/2010/04/using-htmlagilitypack-to-get-and-post.html
我使用 HtmlAgilityPack 和 fiddler 的组合来观察流量。使用 fiddler,您可以看到正在向服务器发送的帖子,然后复制它。然后您可以捕获 cookie 数据来保存登录会话。从那里开始,就可以正常浏览网站了。
有几点需要注意,如果您使用登录来获取数据,则可能会有 cookie。如果是这样,您需要在 cookieContainer 中设置它。这是一个示例函数,我用它来将数据发布到 URL。
Cookie 会话功能
I use a combination of HtmlAgilityPack and fiddler to watch the traffic. With fiddler you can see the post that is being made to the server, and just replicate it. Then you can capture the cookie data to save the login session. From there its just normal navigating around the site.
A few things to watch out for, if you use a login to get the data there may be a cookie. If so you need to set it in the cookieContainer. This is a sample function that I use to post data to an url.
Cookie session function