1

我正在尝试在 ExtJS 下拉列表中查找元素列表。我在 stackoverflow 上找到了一个很好的解决方案,尽管它对我不起作用。

C#中的解决方案:

 public void ClickComboItem(IWebElement input, string target)
        {
            input.Click();
            IList<IWebElement> comboItems = _driver.FindElements(By.XPath("//*[contains(@class, 'x-combo-list') and contains(@style, 'visibility: hidden;')]//*[contains(@class, 'x-combo-list-item')]"));
            comboItems.First(item => item.Text.Trim() == target).Click();
        }

这里

我需要自动化的部分如下所示:

<div class="x-ie-shadow" id="ext-gen546" style="z-index: 12004; filter: progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=4); WIDTH: 351px; display: none; height: 301px; top: 186px; left: 1187px;"/>
<div class="x-layer x-combo-list " id="ext-gen544" style="z-index: 12005; position: absolute; width: 350px; height: 302px; visibility: hidden; font-size: 12px; top: -10000px; left: 0px;">
<div class="x-combo-list-inner" id="ext-gen545" style="width: 348px; height: 300px; overflow: auto;">
<div class="x-combo-list-item" _nodup="30813" viewIndex="0">
<div class="x-combo-list-item" _nodup="30813" viewIndex="1">

执行了对指针的实际单击,我可以看到页面上的下拉列表,尽管 comboItem 返回“0”结果。我假设我应该为我的情况正确调整 xPath,尽管在我看来它应该可以工作,只要结构与我上面提到的帖子中的示例非常相似。

4

3 回答 3

1

xPath 似乎不正确。

你给了“可见性:隐藏;”

尝试使用“”可见性:可见;“

public void ClickComboItem(IWebElement input, string target)
{
    input.Click();
    IList<IWebElement> comboItems = _driver.FindElements(By.XPath("//*[contains(@class, 'x-combo-list') and contains(@style, 'visibility: visible;')]//*[contains(@class, 'x-combo-list-item')]"));
    comboItems.First(item => item.Text.Trim() == target).Click();
}
于 2013-06-17T06:20:14.183 回答
0

您可以采取不同的方式而不使用 Xpath

 IWebElement dvInner = driver.FindElement(By.Id("ext-gen545"));
 IList<IWebElement> comboItems = dvInner.FindElements(By.ClassName("x-combo-list-item"));
于 2013-06-17T07:50:38.713 回答
0

尝试使用任何父节点的稳定 id 来实现。基本上使用 xpath-axis 概念。

于 2014-09-30T20:14:38.637 回答