使用对象库等待UI元素

对象库每个项和文件夹都会提供一个由<objectname>Info表示的附加对象。它可以用来访问相应对象的属性,使用它不会直接访问对象,从而避免抛出异常。这个info对象主要用来检查某项的路径是否有效。和该项的超时设置组合,你可以来用它来等待某些元素的出现,例如对话框,文本值和web内容。

C#

// Use the ‘Info’ object to check existence of the  使用Info对象来检查SaveDialog是否存在
// ‘SaveDialog’ item; Method ‘Exists’ uses the timeout  方法Exists会用到对象库中的超时设置
// specified for the ‘SaveDialog’ in the repository
Report.Info(“Exists = ” + repo.SaveDialog.SelfInfo.Exists().ToString());

// Use the ‘Info’ object to check existence of the
// ‘TextOnline’ item which uses the following RXPath:
// statusbar/text[@accessiblename=’Online’]
// This way you can wait with the timeout specified for
// the item within the repository for the text ‘Online’
bool statusTextConnected = repo.MyApp.TextOnlineInfo.Exists();

// Using ‘Info’ objects for validation  如果验证失败,Info对象会抛出异常
// Throws a Ranorex.ValidationException if validation
// fails. Automatically reports success or failed message
// to log file
Validate.Exists(repo.SaveDialog.ButtonOKInfo);

// Validates the existence of the repository item, 使用false参数,避免抛出异常
// but does not throw any exception
Validate.Exists(repo.SaveDialog.ButtonOKInfo,”Check Object ‘{0}'”,false);

VB.NET

‘ Use the ‘Info’ object to check existence of the
‘ ‘SaveDialog’ item; Method ‘Exists’ uses the timeout
‘ specified for the ‘SaveDialog’ in the repository
Report.Info(“Exists = ” & repo.SaveDialog.SelfInfo.Exists().ToString())

‘ Use the ‘Info’ object to check existence of the
‘ ‘TextOnline’ item which uses the following RXPath:
‘ statusbar/text[@accessiblename=’Online’]
‘ This way you can wait with the timeout specified for
‘ the item within the repository for the text ‘Online’
Dim statusTextConnected As Boolean = repo.MyApp.TextOnlineInfo.Exists()

‘ Using ‘Info’ objects for validation
‘ Throws a Ranorex.ValidationException if validation
‘ fails. Automatically reports success or failed message
‘ to log file
Validate.Exists(repo.SaveDialog.ButtonOKInfo)

‘ Validates the existence of the repository item,
‘ but does not throw any exception
Validate.Exists(repo.SaveDialog.ButtonOKInfo, “Check Object ‘{0}'”, False)

Leave a comment

请输入正确的验证码