【问题标题】:How to select option from dynamic dropdown如何从动态下拉列表中选择选项
【发布时间】:2014-07-25 14:03:14
【问题描述】:

我在从动态下拉列表中选择选项时遇到问题。 我已经尝试了几种选择: - 通过从选择列表中选择(在我尝试过的“目标”中(标签、索引、值)) - 通过从 div id="id_language_chzn 中选择(在我尝试过的“目标”中(标签、索引、值))

什么都不行!

代码在这里:http://pastebin.com/v3Q7NDGs

如果能在这方面帮助我, 西门

【问题讨论】:

  • 我看到了您的代码,但我不明白,您使用的是哪种语言?我在python中遇到了同样的问题......也许我可以帮助你,因为功能相似
  • @Lara 我在 selenium IDE 中使用 html/css。

标签: selenium selenium-ide


【解决方案1】:

页面加载后使用一点延迟,很可能JS没有完全初始化。 http://release.seleniumhq.org/selenium-core/1.0/reference.html#pause 同样对于这个Chosen问题,点击动态创建的元素本身,不要使用html表单元素。

【讨论】:

  • 延迟似乎不起作用。选择选项时没有JS加载。
【解决方案2】:

我会这样做:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
By ddLocator = By.xpath(".//select[1]");
By items = By.xpath(".//option");
ByChained comboBox1 = new ByChained( ".//select[1]", ".//option" ); 
List<WebElement> allOptions = driver.getElements( comboBox1 );
for ( WebElement we : allOptions ) {
  // do something here
}

【讨论】:

    【解决方案3】:

    好的,selenium IDE 在取出所选选项时出现了一些问题。我使用了 webdriver,它有所帮助。

    代码如下:

    driver.findElement(By.cssSelector("a.class > span")).click(); 
    driver.findElement(By.id("id_name[1]")).click();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-11
      • 2017-03-08
      • 2021-07-16
      • 1970-01-01
      • 2018-12-15
      • 2017-05-19
      相关资源
      最近更新 更多