[英]The playback failed to find the control with the given search properties in Coded UI
I'm new in Coded UI test, so here's a "simple" question: 我是Codeed UI测试的新手,所以这是一个“简单”的问题:
Trying to navigate through the options of a menu, i've recorded actions nad tried to playback. 尝试浏览菜单选项时,我记录了尝试回放的动作。 I got the following message:
The playback failed to find the control with the given search properties
我收到以下消息:
The playback failed to find the control with the given search properties
Here's the code generated by recording tool: 这是录制工具生成的代码:
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));
}
Is there a way to catch those elements by some kind of locators(these elements doesn't have id)? 有没有办法通过某种定位器来捕获那些元素(这些元素没有id)? Something like this:
像这样:
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;
}
}
Here's the menu: 这是菜单:
One of the interesting things about playback of CODEDUI is that it does not necessarily take into account the time factors of the User during recording. 关于CODEDUI回放的有趣的事情之一是,它不必在录制过程中考虑用户的时间因素。 These are the things I've learned over the years about this type of error...
这些是我多年来就这类错误学到的东西...
Go into the UI map and change the FilterProperty
for InnerText
to a SearchProperty
. 进入UI映射并将
InnerText
的FilterProperty
更改为SearchProperty
。 Search properties are applied first -- if it finds one exact match, it doesn't even look at Filter properties. 首先应用搜索属性-如果找到一个完全匹配的内容,它甚至不会查看过滤器属性。 In this case, the most important thing about the control (the text value) is a filter property.
在这种情况下,关于控件(文本值)最重要的是过滤器属性。
It's trying to find a <LI>
tag with no ID. 它正在尝试查找没有ID的
<LI>
标记。 It undoubtedly finds multiple matches. 无疑会找到多个匹配项。 Then it applies the filter properties, which are probably things that vary from page load to page load.
然后,它应用过滤器属性,这些属性可能因页面加载而异。
You could also apply an ID
property to the <LI>
tags, then update the UI map search properties so that it searches for that specific ID, which would also solve the problem. 您还可以将
ID
属性应用于<LI>
标记,然后更新UI映射搜索属性,以便它搜索该特定ID,这也将解决问题。
In general, when you're using Coded UI with web applications, it's a good idea to make sure everything on the page has a unique "ID" attribute. 通常,当在Web应用程序上使用编码UI时,最好确保页面上的所有内容都具有唯一的“ ID”属性。 This makes it much easier for Coded UI to zero in on the page elements you're trying to interact with.
这使得编码UI在要与之交互的页面元素上轻松置零。
I had a similar problem and came across this. 我遇到了类似的问题,并遇到了这个问题。 In my case, I was using older CodedUI tests that were recorded with a slightly older version (12.0.21005.1).
就我而言,我使用的是较旧的CodedUI测试,该测试是用稍旧的版本(12.0.21005.1)记录的。 Same error message ("The playback failed to find the control with the given search properties") and the error specifically mentioned a Text input that it couldn't find on the page.
出现相同的错误消息(“播放未能找到具有给定搜索属性的控件”),错误特别提到了在页面上找不到的文本输入。
The answer for me was that the BrowserWindow object was losing it's reference when a the page changed (after clicking on a link on a previous page). 对我来说,答案是页面更改时(单击上一页的链接后),BrowserWindow对象丢失了对其的引用。 I don't know why.
我不知道为什么
The solution was to call BrowserWindow.TryFind() in a log statement and then everything worked find as previously recorded. 解决方案是在一条日志语句中调用BrowserWindow.TryFind(),然后一切正常,如先前记录的那样查找。
Jus thought I'd share in case somebody else has this issue. Jus认为我愿意与别人分享这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.