【问题标题】:How the fetch the value of textBox Using Javascript in Selenium webDriver? [duplicate]如何在 Selenium webDriver 中使用 Javascript 获取 textBox 的值? [复制]
【发布时间】:2019-12-06 16:01:13
【问题描述】:

我想获取输入标签中的文本,这在我的 HTML 中不可用。所以我必须使用 JS 来获取价值。但是在eclipse中运行时我得到了null。我在下面的屏幕截图中添加了 HTML 和 Selenium 代码。

【问题讨论】:

  • 你试过driver.findElement(By.xpath("//input[@id = 'estimatedDepositRate']")).getAttribute("value")吗?你需要使用javascript吗? off:这是一个输入,而不是文本框
  • html Dom 中没有 value 属性。因此我没有尝试
  • 如果您在Inspect 中没有看到它,这并不意味着没有value 属性。
  • 它正在工作...谢谢

标签: javascript java html selenium selenium-webdriver


【解决方案1】:

在 Javascript 中:

document.getElementById("estimatedDepositRate").value;

这可以使用 JavascriptExecutor 在 selenium 中实现:

String estimatedDepositRate  = ((JavascriptExecutor) driver).executeScript("return document.getElementById("estimatedDepositRate").value");

普通代码:

driver.findElement(By.id("estimatedDepositRate")).getAttribute("value")

注意:如果您遇到任何错误,请将estimatedDepositRate 值转换为String

【讨论】:

    猜你喜欢
    • 2020-01-17
    • 1970-01-01
    • 2019-03-11
    • 2018-07-01
    • 2014-01-08
    • 2018-10-22
    • 2016-06-28
    • 2020-12-23
    • 2012-07-10
    相关资源
    最近更新 更多