CodedUI查找没有ID的下级列表项?

时间:2016-10-20 15:17:07

标签: c# unit-testing automated-tests coded-ui-tests

我正在使用C#试验CodedUI并且遇到了一些麻烦。我有一个<ul>包含一个ID,然后是一个非唯一标识的<li>,其中包含多个<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> 标记,如下所示:

Mouse.Click(...)

如何在包含我的<a>标记的第二个列表项(或<a>内)上设置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) 并测试&#34;历史&#34;?< / p>

我已经尝试过我能想到的每个组合来指定这个标签,一直到指定父级并尝试获取&#34; TagInstance&#34;:

function getWorkingDays($startDate, $endDate)
{
    $begin = strtotime($startDate);
    $end   = strtotime($endDate);
    if ($begin > $end) {
        echo "startdate is in the future! <br />";

        return 0;
    } else {
        $no_days  = 0;
        $weekends = 0;
        while ($begin <= $end) {
            $no_days++; // no of days in the given interval
            $what_day = date("N", $begin);
            if ($what_day > 5) { // 6 and 7 are weekend days
                $weekends++;
            };
            $begin += 86400; // +1 day
        };
        $working_days = $no_days - $weekends;

        return $working_days;


    }
}

导致无法找到控件。任何人都可以帮我这个吗?

1 个答案:

答案 0 :(得分:0)

这样的事情:

    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);       
    }

其中方法GetPaneId()如下所示:

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