播放未能找到与编码的UI给定的搜索属性控制 [英] The playback failed to find the control with the given search properties in Coded UI

查看:365
本文介绍了播放未能找到与编码的UI给定的搜索属性控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编码的UI测试新的,所以这里有一个简单的问题:

I'm new in Coded UI test, so here's a "simple" question:

尝试通过菜单选项进行导航,我录的行动NAD试图播放。我得到了以下信息:播放未能找到与给定的搜索属性控制

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

下面是生成的代码通过记录工具:

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)? 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:

推荐答案

进入到UI映射,并修改 FilterProperty 的InnerText SearchProperty 。搜索属性首先应用 - 如果它找到一个确切的匹配,它甚至不看过滤器属性。在这种情况下,有关控制(文本值),最重要的是一个过滤器属性。

Go into the UI map and change the FilterProperty for InnerText to a 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.

它试图找到一个< LI> 没有ID标签。这无疑是找到多个匹配。然后应用滤镜的属性,这可能是东西有所不同页面加载到页面加载。

It's trying to find a <LI> tag with no ID. It undoubtedly finds multiple matches. Then it applies the filter properties, which are probably things that vary from page load to page load.

您也可以申请一个 ID 属性设置为< LI> 标签,然后更新UI地图搜索属性,这样它会搜索特定ID,这也将解决这个问题。

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.

在一般情况下,当你重新使用编码的UI与Web应用程序,这是一个好主意,使在页面上确保一切都有一个唯一的id属性。这使得它更容易为编码的UI到零上你想与之交互的页面元素。

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. This makes it much easier for Coded UI to zero in on the page elements you're trying to interact with.

这篇关于播放未能找到与编码的UI给定的搜索属性控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆