(C#) A demo on how to auto fill out the "account" value in log in web page in "WebBrowser" control.

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.

 

        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.

转载于:https://www.cnblogs.com/lucasluo/archive/2010/11/27/1890016.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值