简体   繁体   English

播放未能在编码的UI中找到具有给定搜索属性的控件

[英]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... 这些是我多年来就这类错误学到的东西...

  1. The current window or control is not the Top Most window. 当前窗口或控件不是“最热门”窗口。
  2. The search criteria is too restrictive, ask yourself is there something in this search criteria that's not the same as the recording. 搜索条件过于严格,请问自己,该搜索条件中是否有与录音不同的内容。 In this case I can see a possible issue with this : "data-value=\\"201405231131464799\\"" Is that number the same every time? 在这种情况下,我可以看到一个可能的问题:“ data-value = \\” 201405231131464799 \\“”“该数字每次都相同吗?
  3. The control is searched for before it is ready to be done. 在准备好完成之前,先搜索该控件。 This is fixed by calling (in your case) Custom.WaitForReady() 通过调用(在您的情况下)Custom.WaitForReady()可以解决此问题。
  4. I have also seen this (which I don't fully understand) because these recording don't have X,Y coordinates; 我也看到了这一点(我不完全理解),因为这些记录没有X,Y坐标。 except for the Point defined in the second parameter. 第二个参数中定义的Point除外。 If the recording screen size and the playback screen size are NOT the same, sometimes (but not always) the playback "can't find the control". 如果录制屏幕尺寸和播放屏幕尺寸不同,则有时(但并非总是)播放“找不到控件”。 You can try to omit the point parameter. 您可以尝试省略point参数。
  5. The element is simply not visible. 该元素根本不可见。

Go into the UI map and change the FilterProperty for InnerText to a SearchProperty . 进入UI映射并将InnerTextFilterProperty更改为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.

相关问题 在Chrome浏览器中运行测试时,编码的Ui Playback无法找到给定的搜索控件 - Coded Ui Playback failed to find given search control while running test in chrome browser 播放未能找到具有给定搜索属性错误的控件 - The playback failed to find the control with the given search properties error 编码的UI,文本控件的搜索属性 - Coded UI, search properties for text controls 什么是编码的UI测试生成器中的搜索,控件特定和通用 - What are Search, Control Specific and Generic in Coded UI Test Builder 编码用户界面的隐藏控件 - Hidden control at Coded UI 编码的用户界面-找不到要测试的特定控件 - Coded UI- Can't find Specific Control to Test 编码 ui:另一个控件正在阻止控件 - Coded ui: Another control is blocking the control 在具有相同相对路径的URL链接上获取编码的UI异常“无法对阻止的控件执行操作” - Getting Coded UI exception “Failed To Perform Action On Blocked Control” on a url links with same relative path 在编码的用户界面中找不到定义的属性不足的控件 - Can't find controls that don't have enough defined properties in Coded UI 仅使用编码的ui无法在几台计算机上找到文本框控件 - Unable to find text box control on few machine only using coded ui
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM