zoukankan      html  css  js  c++  java
  • (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.

  • 相关阅读:
    函数
    函数式编程
    高级特性
    内建的数据结构
    条件语句和循环语句
    java_基础——用代码编译.java文件+加载class文件
    日期格式私人定制——SimpleDateFormat
    java7(3)——增强的catch之自动释放资源
    java7(2)——使用mutilcatch注意事项
    java7(1)——反编译深入理解增强的switch(读字节命令实战)
  • 原文地址:https://www.cnblogs.com/lucasluo/p/1890016.html
Copyright © 2011-2022 走看看