C # Use UIA to simulate click operations

Source: Internet
Author: User

Previously, I wrote an article on C # using spy for simulated operations. A friend of mine mentioned UIA in his message, today, we also use UIA to implement a new control test on the VNC form.

Goals

Enter 192.168.2.200 in the server box.

Automatically click the Options button.

Tool Introduction

Uispy, use this tool to find the form. You can download uispy from my csdn.

In uispy, find the window to be operated and click each line. The window is automatically displayed in the red border box.

Code Writing

The execution result is as follows.

// Find the form var desktop = automationelement named VNC Viewer: connection details. rootelement; // obtain the desktop // create a search condition, which indicates that the name attribute is used and the value is the name of the form we need to find. VaR condition = new propertycondition (automationelement. nameproperty, "VNC Viewer: connection details"); // find the first form that meets the conditions. vaR window = desktop. findfirst (treasure. children, condition); // find the Options button on the required form and click var btncondition = new andcondition (New propertycondition (automationelement. controltypeproperty, controltype. button), new propertycondition (automationelement. nameproperty, "options... "); // find the button var buttonoption = Window. findfirst (treasure. children, btncondition); // get button operation event var clickpattern = (invokepattern) buttonoption. getcurrentpattern (invokepattern. pattern); // execute the event clickpattern. invoke (); // good, the above code is executed smoothly, next we will continue to implement the input result to the text box // use the same method first find the text box var txtcondition = new propertycondition (automationelement. controltypeproperty, controltype. edit); // descendants note that the text box is not a child of the window, so children cannot be used directly. vaR txtbox = Window. findfirst (treasure. descendants, txtcondition); var editpatten = (valuepattern) txtbox. getcurrentpattern (valuepattern. pattern); editpatten. setvalue ("192.168.2.200 ");
References

Http://www.cnblogs.com/coderzh/archive/2009/11/14/1603109.html

Http://www.cnblogs.com/stbchina/archive/2010/01/28/Tech-Trend-of-Microsoft-UI-Automation-Testing-Part-Two.html

C # Use UIA to simulate click operations

Related Article

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.