Wf4.0 practice (17th): implement automatic website robot access

Source: Internet
Author: User

Overview

It sounds incredible to use wf4.0 to automatically access 'Robot. Let's look at the effect in the old way. Let's talk about how to implement it. The final summary is provided.CodeDownload.

This articleArticleI used this 'robot' to play with my blog. Including robot login, robot reply, robot recommendation, robot regular reply, and robot regular recommendation.

In this article, I have prepared four procedures for you.

First process, Google Search

This process is very simple. After workflow1 is started, workflow1 will open your IE browser and navigate to the Google homepage. Then the process will automatically enter the search keyword "Zhu Yulin" in the search box ", and click search automatically.

The first process is as follows:

Step 1: automatically open the Google Homepage

Step 2: automatically enter "Zhu Yulin" in the search box"

Step 3: Click Google search automatically. The search result is as follows:

The first is the domestic baichuan blog of the blog Park.

Process 2: log on to the blog

The process is as follows:

Step 1: automatically open the blog garden logon page:Http://passport.cnblogs.com/login.aspx

Step 2: Enter the user name, password, and password to check

Step 3: Click Log On. The logon is successful, for example:

In this way, you have successfully logged on to the blog Park.

Third stream: blog garden messages and recommendations

Flow chart, add the following section below the second process:

Result 1: Leave a message:

Result 2: recommended:

The last process:

Based on Process 3In this way, you can continuously reply and recommend messages. To prevent websites from frequently replying to messages, you can also add a delay activity to regularly and regularly reply to messages, for example, reply once every five minutes. Haha, everyone knows what to do. The last process is not demonstrated. For details, see the attachment code.

 

Implementation:

Three custom wf4.0 activities are required:

1. access the website's visitpage Activity

[Designer ( Typeof (Visitpagedesigner)]Public   Sealed   Class Visitpage: codeactivity { Public Inargument < String > URL { Get ; Set ;} Public Inargument < Int > Waittime { Get ; Set ;} Protected   Override   Void Execute (codeactivitycontext context ){ Object Missing = system. reflection. Missing. value; browser. theinstance. navigate (URL. Get (context ), Ref Missing, Ref Missing, Ref Missing, Ref Missing); browser. theinstance. Visible = True ; While (Browser. theinstance. Busy) thread. Sleep (waittime. Get (context ));}}

There are two attributes: the URL for accessing the page and the duration waittime

2. inputdata activity for inputting data to the webpage. inputdataextension is used as an example here.

[Designer (Typeof (Inputdataextensiondesigner)] Public   Sealed   Class Inputdataextension: codeactivity { Private   Const   String Input_type_text =" Text "; Private   Const   String Input_type_radio =" Radio "; Private   Const  String Input_type_check =" Checkbox "; Public Inargument < String > Type { Get ; Set ;} Public Inargument < String > Inputid { Get ; Set ;} Public Inargument < String > Value {Get ; Set ;} Protected   Override   Void Execute (codeactivitycontext context) {ihtmldocument2 Doc = browser. theinstance. Document As Ihtmldocument2; ihtmlelement body = Doc. Body; ihtmlelementcollection children = body. All As Ihtmlelementcollection; Foreach (Ihtmlelement child In Children ){ If (Child = Null )Continue ; If (Child. ID! = Null & Child. ID = inputid. Get (context) {Child. innertext = value. Get (context );}}}}

3. Click the click activity of the page button. Here, the clickextension activity is used as an example:

[Designer ( Typeof (Clickdesigner)] Public   Sealed   Class Clickextension: codeactivity { Public Inargument < String > Clickname { Get ;Set ;} Protected   Override   Void Execute (codeactivitycontext context) {ihtmldocument2 Doc = browser. theinstance. Document As Ihtmldocument2; ihtmlelement body = Doc. Body; ihtmlelementcollection children = body. All As Ihtmlelementcollection; Foreach (Ihtmlelement child In Children ){ If (Child = Null ) Continue ;If (Child. ID! = Null & Child. ID = clickname. Get (context) {Child. Click ();} Else   If (Child. classname! = Null & Child. classname =" Diggit ") {Child. Click ();}}}}

To sum up, you just need to move your mouse and keyboard. Now both inputdata and click have been customized for you. You just need to move your eyes to see and use your brain to think. :)

Summary:

This article uses wf4.0 to customize some user actions. You may say this is of little use. It is a new style at most, and it is not very useful for actual development. In fact, before this article, I have written an article: wf4.0 practice (V): Implement an intuitive and scalable automatic testing framework, this article develops a test process for a simple windowform. In this article, you can use this article to customize some test procedures and test your website.

Is wf4.0 interesting. Start learning. Interesting. Don't forget to recommend it. :)

Code:Http://files.cnblogs.com/zhuqil/VisitWebSite.rar

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.