【问题标题】:Button not getting enabled upon selection of value in dropdown Selenium在下拉 Selenium 中选择值时按钮未启用
【发布时间】:2016-05-18 10:43:15
【问题描述】:

我的应用程序中有一个“继续”按钮,在选择下拉列表中的值时启用,即“年份”。

当为此使用 Selenium 时,即使在选择此值后,按钮也不会启用,因此测试失败,因为 Selenium 无法单击禁用的按钮。

当手动选择此下拉菜单时,按钮被启用

如何使用 Selenium WebDriver 处理这种情况

【问题讨论】:

  • 尝试在点击按钮之前添加等待会起作用
  • 已经这样做了,不起作用
  • 你能分享一下下拉列表的 HTML,以及到目前为止你尝试过的 WebDriver 代码吗?

标签: testing selenium-webdriver ui-automation pageobjects


【解决方案1】:

hi just after selection value form dropdown 在点击前实现这段代码

WebDriverWait wait = new WebDriverWait(driver,20);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("your path= 
when button is disabled as on enable path will change")));

// 现在是按钮的点击代码

或者你也可以像下面这样尝试

在从下拉列表中选择值之后,在单击按钮之前,请单击页面上的其他位置,有时这会有所帮助

更新

在浏览完按钮的html后,类名略有不同,请仔细查看

Class name when button is disabled  = LA-right LA-btn payment-continue
Class name when button is enabled   = LA-right LA-btn payment-continue enable

所以请使用 xpath 作为第一个场景 //*[@class='LA-right LA-btn payment-continue'] 或 css 选择器 = By.cssSelector(".LA-right.LA-btn.payment-continue") 现在我想这会有所帮助

【讨论】:

  • 好的会尝试使用这个
  • 尝试点击页面某处,也不起作用
  • 这也不起作用,因为启用和禁用按钮或链接的 XPATH 保持不变,即 //*[@id="payment"]/div[2]/div/a
  • 复制链接 HTML 已禁用:Continue 启用:继续
  • ElementNotVisible 异常
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-24
  • 1970-01-01
  • 2021-04-26
  • 2020-09-12
  • 1970-01-01
  • 2020-10-18
  • 1970-01-01
相关资源
最近更新 更多