Sun*_*mar 3 javascript selenium selenium-webdriver
有一个隐藏的输入字段,我正在尝试插入特定的日期值.该字段最初生成一个值,用户可以从中选择适当的值.该页面的源代码如下所示:
<div id="change_img">
<img width="80" height="30" border="1" src="http://jntuh.ac.in/results/images/CaptchaSecurityImages.php?width=100&height=50&characters=5&code=ryyrh">
<br>
<input id="code" type="hidden" value="ryyrh" name="code">
</div>
Run Code Online (Sandbox Code Playgroud)
使用WebElement的getAttribute方法.在你的情况下,它将是:
WebElement hiddenInput = driver.findElement(By.id("code"));
String value = hiddenInput.getAttribute("value");
Run Code Online (Sandbox Code Playgroud)
如果由于任何原因你需要用javascript(你的问题特别要求js),那么这段代码应该工作:
String script = "return document.getElementById('code').getAttribute('value');";
String value = ((JavascriptExecutor) driver).executeScript(script).toString();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13406 次 |
| 最近记录: |