CodedUI Find lower level List Item without an ID?

百般思念 提交于 2019-12-12 07:02:38

问题


I am experimenting with CodedUI using C# and am having some trouble. I have got a <div> containing an ID, and then a non-uniquely identified <ul> with several <li> tags like the below:

<div id="uniqueIdValue" class"long_class" activetabindex="0" sfwtabcontainer="true">
   <ul class="long_class2">::before
      <li class="sharedListItemClass" sfwtabheader="true">...</li>
      <li class="sharedListItemClass" sfwtabheader="true">
           <a href="#someValue">History</a>
      </li>
      <li class="sharedListItemClass" sfwtabheader="true">...</li>
      ::after
   </ul>

How can I setup a Mouse.Click(...) on the the second list item (or the <a> within) containing my <a> tag with test of "History"?

I have tried every combination I can think of to specify this tag by itself, all the way up to specifying the parent and trying to get the "TagInstance":

var container = new HtmlControl(_bw);
HtmlDiv nameForDiv = new HtmlDiv(container);
nameForDiv.SearchProperties[HtmlDiv.PropertyNames.Id] = "uniqueDivIdentifier";
nameForDiv.SearchProperties[HtmlDiv.PropertyNames.Class] = "long Multiple_Classes";

var historyTab = new HtmlHyperlink(nameForDiv);
historyTab.SearchProperties[HtmlHyperlink.PropertyNames.Href] = "#someValue";
historyTab.SearchProperties[HtmlHyperlink.PropertyNames.TagInstance] = "2";

Mouse.Click(historyTab)

Resulting in the control cannot be found. Can anyone help me with this?


回答1:


Something like this:

    var browser = BrowserWindow.Launch("url");

    private void ClickLink()
    {

        var parent = GetPaneID(browser, "uniqueIdValue");
        var child = parent.GetChildren()[0];
        var child2 = child.GetChildren()[1];
        var child3 = child2.GetChildren()[0];
        Mouse.Click(child3);       
    }

where method GetPaneId() looks like this:

    public HtmlDiv GetPaneID(UITestControl parent, string id)
    {
        var gpane = new HtmlDiv(parent);
        gpane.SearchProperties.Add(HtmlDiv.PropertyNames.Id, id);
        return gpane;
    }


来源:https://stackoverflow.com/questions/40158387/codedui-find-lower-level-list-item-without-an-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!