【问题标题】:Selenium WebDriver ExtJS drop-downSelenium WebDriver ExtJS 下拉菜单
【发布时间】:2017-02-14 03:06:11
【问题描述】:

我正在尝试在 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();
        }

来自here

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

<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,尽管在我看来它应该可以工作,只要结构与我上面提到的帖子中的示例非常相似。

【问题讨论】:

  • 能否粘贴html代码,以便我们提供更相关的答案?

标签: extjs selenium automation webdriver


【解决方案1】:

xPath 好像不正确。

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

尝试使用 ""visibility: visible;"

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

【讨论】:

  • 我也试过了。不幸的是,不起作用。如我所见,我找不到 //*[contains(@class, 'x-combo-list') 和 contains(@style, 'visibility: visible;')] 是否还有其他可能找到这个元素.. ?
  • @user1177636:返回 0 个元素。
【解决方案2】:

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

 IWebElement dvInner = driver.FindElement(By.Id("ext-gen545"));
 IList<IWebElement> comboItems = dvInner.FindElements(By.ClassName("x-combo-list-item"));

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-21
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      • 2014-05-29
      • 1970-01-01
      相关资源
      最近更新 更多