高级代码示例
你也可以直接代码中通过API方法"Find"使用RanoreXPath表达式来查找界面上的元素。可以使用"Host.Local"作为根元素来查找,或者重用像对象库中项这样存在的adapter作为开始节点进行查找。
C#
// Create Ranorex.Button adapter using 'FindSingle' method // from Host.Local (starting at root node) with absolute RanoreXPath // Note: ElementNotFound exception is thrown if item is not found within // the specified timeout of 2000 ms. Ranorex.Button addButtonVar1 = Host.Local.FindSingle<Ranorex.Button>("/form[@controlname='formVipApplication']/button[@controlname='btAdd']",2000); addButtonVar1.MoveTo();
// Alternatively you can use the 'TryFindSingle' method to prevent // a test case from failing because of an exception thrown if // the element is not found within the specified timeout of 2000 ms Ranorex.Button addButtonVar2 = null; bool found = Host.Local.TryFindSingle<Ranorex.Button>("/form[@controlname='formVipApplication']/button[@controlname='btAdd']", 2000, out addButtonVar2); // Move mouse pointer to button addButtonVar2.MoveTo();
// Request a list of buttons shown from the VIP Database application // and create a screenshot for each button in the report file IList<Ranorex.Button> buttonList = Host.Local.Find<Ranorex.Button>("/form[@controlname='formVipApplication']/button",500); foreach (Ranorex.Button bt in buttonList) { Report.Screenshot(bt); }
// Using find methods in combination with existing Ranorex repository items Ranorex.Button btAdd = repo.MyApp.Self.FindSingle<Ranorex.Button>("button[@controlname='btAdd']",2000);
VB.NET
' Create Ranorex.Button adapter using 'FindSingle' method ' from Host.Local (starting at root node) with absolute RanoreXPath ' Note: ElementNotFound exception is thrown if item is not found within ' the specified timeout of 2000 ms. Dim addButtonVar1 As Ranorex.Button = Host.Local.FindSingle(Of Ranorex.Button)("/form[@controlname='formVipApplication']/button[@controlname='btAdd']", 2000) addButtonVar1.MoveTo()
' Alternatively you can use 'TryFindSingle' method to prevent ' a test case from failing because of an exception thrown if ' the element is not found within the specified timeout of 2000 ms Dim addButtonVar2 As Ranorex.Button = Nothing Dim found As Boolean = Host.Local.TryFindSingle(Of Ranorex.Button)("/form[@controlname='formVipApplication']/button[@controlname='btAdd']", 2000, addButtonVar2) ' Move mouse pointer to button addButtonVar2.MoveTo()
' Request a list of buttons from the VIP Database application ' and create a screenshot for each button in the report file Dim buttonList As IList(Of Ranorex.Button) = Host.Local.Find(Of Ranorex.Button)("/form[@controlname='formVipApplication']/button", 500) For Each bt As Ranorex.Button In buttonList Report.Screenshot(bt) Next
' Using find methods in combination with existing Ranorex repository items Dim btAdd As Ranorex.Button = repo.MyApp.Self.FindSingle(Of Ranorex.Button)("button[@controlname='btAdd']", 2000)

浙公网安备 33010602011771号