播放无法在Coded UI中找到具有给定搜索属性的控件
我是Coded UI测试的新手,所以这是一个“简单”的问题:
试图浏览菜单的选项,我记录了尝试播放的动作。 我收到以下消息: The playback failed to find the control with the given search properties
这是录制工具生成的代码:
public void NavegarSituacao() { #region Variable Declarations HtmlCustom uINotíciasCustom = this.UIHttpcmshomepsafecomIWindow.UIHttpcmshomepsafecomDocument.UINotíciasCustom; HtmlCustom uIEntretenimentoCustom = this.UIHttpcmshomepsafecomIWindow.UIHttpcmshomepsafecomDocument.UIEntretenimentoCustom; HtmlCustom uIMulherCustom = this.UIHttpcmshomepsafecomIWindow.UIHttpcmshomepsafecomDocument.UIMulherCustom; HtmlCustom uIEsportesCustom = this.UIHttpcmshomepsafecomIWindow.UIHttpcmshomepsafecomDocument.UIEsportesCustom; HtmlCustom uIHomemCustom = this.UIHttpcmshomepsafecomIWindow.UIHttpcmshomepsafecomDocument.UIHomemCustom; HtmlCustom uITecnologiaCustom = this.UIHttpcmshomepsafecomIWindow.UIHttpcmshomepsafecomDocument.UITecnologiaCustom; HtmlCustom uIVídeosCustom = this.UIHttpcmshomepsafecomIWindow.UIHttpcmshomepsafecomDocument.UIVídeosCustom; #endregion // Click 'Notícias' custom control Mouse.Click(uINotíciasCustom, new Point(89, 21)); // Click 'Entretenimento' custom control Mouse.Click(uIEntretenimentoCustom, new Point(90, 15)); // Click 'Mulher' custom control Mouse.Click(uIMulherCustom, new Point(90, 9)); // Click 'Esportes' custom control Mouse.Click(uIEsportesCustom, new Point(84, 18)); // Click 'Homem' custom control Mouse.Click(uIHomemCustom, new Point(82, 16)); // Click 'Tecnologia' custom control Mouse.Click(uITecnologiaCustom, new Point(85, 8)); // Click 'Vídeos' custom control Mouse.Click(uIVídeosCustom, new Point(70, 11)); }
有没有办法通过某种定位器捕获这些元素(这些元素没有id)? 像这样的东西:
public HtmlCustom UIHomemCustom { get { if ((this.mUIHomemCustom == null)) { this.mUIHomemCustom = new HtmlCustom(this); #region Search Criteria this.mUIHomemCustom.SearchProperties["TagName"] = "LI"; this.mUIHomemCustom.SearchProperties["Id"] = null; this.mUIHomemCustom.SearchProperties[UITestControl.PropertyNames.Name] = null; this.mUIHomemCustom.FilterProperties["Class"] = null; this.mUIHomemCustom.FilterProperties["ControlDefinition"] = "data-value=\"201405231131464799\""; this.mUIHomemCustom.FilterProperties["InnerText"] = "Homem"; this.mUIHomemCustom.FilterProperties["TagInstance"] = "8"; this.mUIHomemCustom.FilterProperties["Xpath"] = "#default > div.wrapper > div.menu > div > ul > li:nth-child(5)"; this.mUIHomemCustom.WindowTitles.Add("http://cms.home.psafe.com/"); #endregion } return this.mUIHomemCustom; } }
这是菜单:
进入UI映射并将InnerText
的FilterProperty
更改为SearchProperty
。 首先应用搜索属性 – 如果找到一个完全匹配,它甚至不会查看filter属性。 在这种情况下,控件(文本值)最重要的是filter属性。
它试图找到一个没有ID的
标签。 毫无疑问,它会找到多个匹配项。 然后它应用filter属性,这些属性可能是从页面加载到页面加载的变化。
您还可以将ID
属性应用于
标记,然后更新UI映射搜索属性,以便它搜索该特定ID,这也可以解决问题。
通常,当您将Coded UI与Web应用程序一起使用时,最好确保页面上的所有内容都具有唯一的“ID”属性。 这使得Coded UI更容易归零您尝试与之交互的页面元素。
关于CODEDUI播放的一个有趣的事情是它不一定考虑用户在录制期间的时间因素。 这些是我多年来就这类错误所学到的东西……
- 当前窗口或控件不是Top Most窗口。
- 搜索条件过于严格,请问自己此搜索条件中是否存在与录制内容不同的内容。 在这种情况下,我可以看到一个可能的问题:“data-value = \”201405231131464799 \“”每次该数字是否相同?
- 在准备完成之前搜索控件。 通过调用(在您的情况下)Custom.WaitForReady()来解决此问题
- 我也看过这个(我不完全理解),因为这些录音没有X,Y坐标; 除了第二个参数中定义的Point。 如果录制屏幕尺寸和播放屏幕尺寸不相同,有时(但不总是)播放“无法找到控件”。 您可以尝试省略point参数。
- 该元素根本不可见。
我遇到了类似的问题并遇到了这个问题。 在我的情况下,我使用较旧的CodedUI测试,这些测试使用较旧的版本(12.0.21005.1)进行记录。 相同的错误消息(“播放无法找到具有给定搜索属性的控件”)并且错误特别提到了在页面上找不到的文本输入。
对我来说,答案是当页面发生变化时(在点击上一页的链接后),BrowserWindow对象丢失了它的引用。 我不知道为什么。
解决方案是在日志语句中调用BrowserWindow.TryFind(),然后按先前记录的方式查找所有工作。
如果其他人有这个问题,Jus认为我会分享。
- 在不使用IDbContextFactory的情况下编写第一个自定义连接字符串和迁移代码
- 当为输入字段asp.net mvc输入不正确的数据类型时,覆盖错误消息(值’xxx’对Age无效)
- GUID的哪一部分最值得保留?
- 在二进制文件的中间插入字节
- 如何确定GDI +中两条线的交点?
- 如何从ASP.NET MVC自定义IdentityUser模型获取用户配置文件数据?
- 在创建窗口句柄之前,无法在控件上调用Invoke或BeginInvoke
- 有没有办法在protobuf-net中使用IReadOnlyCollection / IReadOnlyList
- Roslyn:如何使用Roslyn C获取DeclarationSyntax的命名空间#