简体   繁体   English

CodedUI GetChildren()不返回带有HEADER,SECTION,ARTICLE,NAV等HTML5标签的子级

[英]CodedUI GetChildren() doesn't return children with HTML5 tags like HEADER, SECTION, ARTICLE, NAV

In codedUI I am unable to traverse by GetChildren() method in an html page with HTML5 tags. 在codedUI中,无法通过带有HTML5标签的html页面中的GetChildren()方法遍历。

My Html structure is like this. 我的HTML结构是这样的。

HTML
  |-BODY
      |-DIV id="pagetop"
         |- HEADER class="headerclass"
         |- NAV class="navclass"
         |- SECTION class="sectionclass"
         |- FOOTER class="footerclass"
         |- DIV id="lastdiv"

Issue: On doing GetChildren() on "pagetop" div control, only 1 result is returned having "lastdiv" div control in it. 问题:在“ pagetop” div控件上执行GetChildren()时,仅返回其中包含“ lastdiv” div控件的1个结果。 It should return 5 controls instead. 它应该返回5个控件。

I am able to capture the UIMap for SECTION(or other HTML5 tags) and able to traverse backward by GetParent() method, but the other way is not working. 我能够捕获SECTION(或其他HTML5标记)的UIMap,并能够通过GetParent()方法向后遍历,但是另一种方法不起作用。

SECTION.GetParent() = DIV id="pagetop"  [Works as expected]
SECTION.GetParent().GetChildren() = Only 1 result [This is wrong, should be 5]

Is there an issue with traversing HTML5 tags in codedui? 在codedui中遍历HTML5标签是否存在问题?

Try looking at the child controls of the one control that is found. 尝试查看找到的一个控件的子控件。 I am not aware of anything that says the HTML structure you show MUST be represented with exactly the same number of levels. 我不知道有什么可以说您显示的HTML结构必须以完全相同的级别数表示。 Phrasing that differently, the UI Controls might have extra levels than the minimum that appear to be necessary for the HTML structure. 换个说法,UI控件的级别可能比HTML结构所需的最低级别高。

To understand how the HTML is represented you could use the Coded UI cross-hairs tool. 要了解HTML的表示方式,您可以使用编码UI十字线工具。 Start with one of the five sections (or a child of theirs) and then use the four navigation arrows to move up through the hierarchy to see what items Coded UI can see at each level. 从五个部分之一(或其子部分)开始,然后使用四个导航箭头在层次结构中向上移动,以查看“编码的用户界面”在每个级别上可以看到的项目。

Another approach might be to use recursive code that calls GetChildren() to descend the hierarchy and show exactly what is present at each level. 另一种方法可能是使用调用GetChildren()递归代码来递归层次结构,并确切显示每个级别上存在的内容。 You might use code based on the recursive routine in my answer to this question Recursively locating a UIElement with InnerText in C# but using a small maxDepth and adding some Console.Writeline() or other print statements to display the controls found. 您可能在我对这个问题的回答中使用基于递归例程的代码,在C#中使用InnerText递归地定位UIElement,但使用较小的maxDepth并添加一些Console.Writeline()或其他打印语句以显示找到的控件。

I have filed one bug in VS2013 feedback forum for this issue. 我已在VS2013反馈论坛中针对此问题提交了一个错误。 It can be tracked here: https://connect.microsoft.com/VisualStudio/feedback/details/898599/ 可以在这里跟踪它: https : //connect.microsoft.com/VisualStudio/feedback/details/898599/

Based on suggestions from AdrianHHH, I am currently doing this to get all the children of a control. 根据AdrianHHH的建议,我目前正在这样做,目的是让控件的所有子级都能使用。 This returns all controls including HTML5 controls as HtmlCustom. 这会将所有控件(包括HTML5控件)返回为HtmlCustom。

    private List<UITestControl> GetAllChildren(UITestControl uiTestControl)
    {
        var child = new HtmlControl(uiTestControl);
        child.SearchProperties.Add("InnerText", "", PropertyExpressionOperator.Contains);
        var items = child.FindMatchingControls().ToList();
        var trueChildren = items.Where(i => i.GetParent().Equals(uiTestControl)).ToList();
        return trueChildren;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用HTML5标签有什么好处 <article> , <section> , <figure> , <header> , <footer> , <nav> ? - What is the benefit of using HTML5 tags like <article>, <section>, <figure>, <header>, <footer>, <nav>? 在引擎盖下,HTML5标签(文章,部分,旁边,页眉,页脚)是否像div一样实现? - Under the hood, are HTML5 tags (article, section, aside, header, footer) implemented just like div? 如何使用 <section> 和 <article> HTML5中添加标签? - How to use <section> and <article> tags in HTML5? HTML5 <section> 在里面 <article> 和标题 - HTML5 <section>'s inside <article> and header 设计HTML5语义元素的问题如 <section> , <nav> 和 <article> - Problems styling HTML5 semantic elements such as <section>, <nav> and <article> HTML5标头不随导航菜单调整大小 - HTML5 header doesn't resize with nav menu 如何正确使用HTML5标签的文章和章节? - How to proper use HTML5 tags Article and Section? 在HTML5中,我应该使用文章或部分标签来制作标签吗? - In HTML5 should I use article or section tags to make tabs? HTML 5是新标签header / nav / aside / section等容器,例如div吗? - HTML 5 are the new tags header/nav/aside/section etc containers like div? HTML5语义标签(文章,页脚,标题)的降级问题 - Degradation issues for HTML5 semantic tags (article, footer, header)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM