white学习2(官方网站的内容)

 

Pre-requisites
.NET 3.5 framework

Please look at Configuration in case you want to change the default configuration.

Getting hold of a window

   Application application = Application.Launch("foo.exe");

   Window window = application.GetWindow("bar", InitializeOption.NoCache);

White uses the UI Automation API (UIA) to find controls on a window. UIA communicates to a displayed window via window messages. This find is performed by iterating through all the controls in a window. This can be slow for windows which have a lot of UIItems. White supports position-based caching of UIItem find results to improve performance. WithCache creates a cache of PrimaryUIItems. This cache is not meant to be used directly by automation programs.

Finding a UI Item and performing action

Button button = window.Get<Button>("save");

button.Click();


Finding a UIItem based on SearchCriteria

SearchCriteria searchCriteria =     SearchCriteria.ByAutomationId("name").AndControlType(typeof(TextBox)).AndIndex(2);

TextBox textBox = (TextBox) window.Get(searchCriteria);

textBox.Text = "Anil";

Getting window

Application Windows

List<Window> windows = application.GetWindows(); //Returns a list of all main windows in belonging to an application. It doesn't return modal windows.

Window mainWindow = application.GetWindow("main"); //Returns a window with provided title.


Desktop Windows

List<Window> windows = Desktop.Instance.Windows(); //Returns a list of all main windows on the desktop. It doesn't return modal windows.


Modal windows

Window mainWindow = application.GetWindow("main");

List<Window> modalWindows = mainWindow.ModalWindows(); //list of all the modal windows belong to the window.

Window childWindow = mainWindow.ModalWindow("child"); //modal window with title "child"

childWindow.IsModal; //returns true

window.MessageBox can also be used for getting a message box window, which is special modal window.

Mdi child window
Use it to find a MDI child belonging to a window.

Window window = Desktop.Instance.Windows().Find(obj => obj.Title.Contains("Microsoft Visual Studio"));

if (window == nullreturn;

window.MdiChild(SearchCriteria.ByControlType(ControlType.Pane).AndByText("FooObject.cs"));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值