【问题标题】:FluentWait for dynamically created ListBoxFluentWait 用于动态创建的 ListBox
【发布时间】:2015-05-11 22:24:06
【问题描述】:

我有一个 listbox(droplist) 项目,当我单击 div/span 元素时会动态创建它。但是,当我尝试单击 listbox 时element 在做了一个流利的 Wait 之后,它给我一个错误说

元素在点 (741, 192) 处不可点击。其他元素会收到点击:"

如果我尝试使用Thread.sleep(2000),那么代码运行完美。关于如何解决此问题并使其在fluentWait 中工作的任何想法。我在 ExpectedConditions 类中尝试了 elementTobeClickable,elementSelectionStateToBe,presenceOfElementLocated 方法,它们都抛出相同的错误。我正在使用 ChromeDriver 进行测试。

我的代码和页面的 HTML sn-p 在下面

WebElement elt = driver.findElement(By.xpath("//*[@id='GroupTT']/span[2]/span/span[1]")); //Clicking on the span so that listbox will be activiated

Actions act = new Actions(driver);
act.moveToElement(elt).click().build().perform();       
fWait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//ul[@id='Group_listbox']/li[2]")))); //Thread.sleep(2000) works fine here.
driver.findElement(By.xpath("//ul[@id='Group_listbox']/li[2]")).click();

HTML 片段

<div >
<ul unselectable="on"  id="Group_listbox"  role="listbox" style="overflow: auto; height: auto;">
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-index="0"> Group1 </li>
<li tabindex="-1" role="option" unselectable="on" class="k-item k-state-selected k-state-focused" data-index="1"> Group2 </li>
<li tabindex="-1" role="option" unselectable="on" class="k-item k-state-selected k-state-focused" data-index="1"> Group3 </li>
</ul>
</div>

【问题讨论】:

  • Saifru,我检查了你提到的链接,这些解决方案都没有帮助我。我仍然有同样的问题。此外,我试图弄清楚为什么 fluentWait 不起作用,以及我是否使用了 ExpectedConditions 类的错误方法
  • 这似乎是 ChromeDriver 本身的问题。我以前遇到过。你在其他浏览器上测试过吗?
  • Firefox 浏览器设计存在一些问题,因此我不得不使用 Chrome。

标签: java ajax listbox webdriver fluent


【解决方案1】:

您可以尝试更改 XPath 定位器以通过其内部文本查找元素。

fWait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//li[text() = 'Group2']"))));

【讨论】:

  • 我在尝试您的建议时遇到了同样的问题。但是现在, fWait 末尾的 getText() 似乎起到了作用。 fWait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//ul[@id='Group_listbox']/li[2]")))).getText();
猜你喜欢
  • 2011-05-24
  • 2011-10-13
  • 1970-01-01
  • 2013-09-05
  • 2016-04-18
  • 2014-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多