(C#) A demo on how to auto fill out the "account" value in log in web page in "WebBrowser" control.
2010-11-27 23:39
826 查看
Recently, I saw a question asked in CSDN, and it makes me interested in this kind of problem.
The question:
The question is that, a guy want to auto log in "taobao", and needs to automatically fill out the account and password.
But he has little knowledge in WebBrowser in .NET. So, do not know how to handle this issue.
Solution:
1. Open "https://login.taobao.com/member/login.jhtml".
2. Click "View Source" to see what the "id" of the account textbox is. My case is "TPL_username_1".
3. Drag a "WebBrowser" control onto the Form.
4. Add ”DocumentCompleted" event. Note, this is the main point that we need to concern Because if you want to operate the controls on the web page, you need to get the document property. But in reality, you need to wait a moment in order to get that property, otherwise it will be null. Some people would use Sleep to delay several seconds, but generally, it's not a good idea because you hardly to make sure how long it will spend on getting the document instance. So, use "DocumetnCompleted" event to handle the operations that you'll performe on the web page.
5. Type below code in "DocumentCompleted" event.
6. Debug your application.
7. See the input tag in your WebBrowser control. You'll see the filed already filled out with the value that you set.
The question:
The question is that, a guy want to auto log in "taobao", and needs to automatically fill out the account and password.
But he has little knowledge in WebBrowser in .NET. So, do not know how to handle this issue.
Solution:
1. Open "https://login.taobao.com/member/login.jhtml".
2. Click "View Source" to see what the "id" of the account textbox is. My case is "TPL_username_1".
3. Drag a "WebBrowser" control onto the Form.
4. Add ”DocumentCompleted" event. Note, this is the main point that we need to concern Because if you want to operate the controls on the web page, you need to get the document property. But in reality, you need to wait a moment in order to get that property, otherwise it will be null. Some people would use Sleep to delay several seconds, but generally, it's not a good idea because you hardly to make sure how long it will spend on getting the document instance. So, use "DocumetnCompleted" event to handle the operations that you'll performe on the web page.
5. Type below code in "DocumentCompleted" event.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { webBrowser1.Document.GetElementById("TPL_username_1").SetAttribute("value", "lucasluo"); }
6. Debug your application.
7. See the input tag in your WebBrowser control. You'll see the filed already filled out with the value that you set.
相关文章推荐
- EF 6.0 The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. c#中的时间
- How to deal with the "ErrorWebPart" error displayed in the web part maintenance page
- How to pass a value from User Control to the Page
- How to Capture the Row Selected on Search Page In a Variable?
- How To Determine When a Page Is Done Loading in WebBrowser Control
- How To Retrieve the URL of a Web Page from an ActiveX Control
- Using Timer to get history values from EDNA database, an error is prompted in the page : "Sys.WebForms.PageRequestManagerTimeout
- How to get IOleSite interface of the WebBrowser in an ActiveX control
- how can i change the back color on mouse out to the color specified in gridview
- How to set the DefaultButton in a Page Based on ASP.NET Master Page
- How to pass ViewState value from web form page to web user control page?
- how to auto refresh your web page in browser?
- HTML codes: How do I add a "click here to refresh this page" button on my webpage
- How To Turn Up Logging on the Siebel Web Server Extension in Siebel Versions 7.x and 8.x? [ID 477185
- How to get the HTML source of a webpage in Ruby
- How to sort a Map<Key, Value> on the values in Java?
- How to set the default input focus on a field in an HTML web form
- HowTO: Create an Event Log Source in code, without the Permission errors
- [C#/.NET]how to implement web application localization in .net 4.0
- <%@ page language="C#" autoeventwireup="true" inherits="index, App_Web_vsb3n 生成网站后,发布到网站上就提示这个错误