gpt4 book ai didi

javascript - Selenium (Java): Retrieve value from disabled input text field

转载 作者:行者123 更新时间:2023-11-28 14:53:08 25 4
gpt4 key购买 nike

我正在尝试使用 Java 中的 Selenium 从输入字段中检索值。这是相关的 HTML 代码:

<input class="form-control input-sm " id="NameInputID" type="text" maxlength="16" name="NameInput" value="TheValueWanted" readonly="">

我试过:

driver.findElement(By.id("NameInputID")).getText();

driver.findElement(By.id("NameInputID")).getAttribute("value");

它们都没有返回值(空白文本)。我该如何处理?

谢谢!

最佳答案

你可以通过 JavascriptExecutor 试试:

Thread.sleep(3) // add a pause to wait until value of the element will be rendered
JavascriptExecutor je = (JavascriptExecutor) driver;
String script = "return document.getElementById('NameInputID').getAttribute('value');");
String value = je.executeScript(script);

关于javascript - Selenium (Java): Retrieve value from disabled input text field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51382479/

25 4 0
文章推荐: ios - 更新 Firestore 数据库导致 iOS 崩溃
文章推荐: jquery - Google map 街景的可 float div?
文章推荐: javascript - 如何为