我想通過添加一個「待辦事項」,然後按回車測試輸入字段,因爲沒有提交按鈕,但我不斷收到「無法找到包含窗體的錯誤」Keys.ENTER和Keys.RETURN沒有正確地提交一個<input>在硒Java
的Java:
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.xxxxx.com");
//add a todo
WebElement input = driver.findElement(By.name("todo"));
input.sendKeys("Get some groceries");
//this outputs Get some groceries
System.out.println("Text: "+ input.getAttribute("value"));
input.sendKeys(Keys.ENTER); //exception here
我也試過input.submit()
,input.sendKeys(Keys.RETURN)
,並結合他們input.sendKeys("Get some groceries", Keys.RETURN)
但無濟於事 - 他們都給出了同樣的錯誤。
HTML:
<html>
<head>
<title>Todo</title>
<link rel="stylesheet" href="build.css">
</head>
<body>
<section id="content">
<h1>Todo</h1>
<p><input type="text" name="todo" placeholder="What needs to be done?"/></p>
<div id="links">
<a href="/">all</a>
<a href="/complete">complete</a>
<a href="/incomplete">incomplete</a>
</div>
<ul id="todos"></ul>
</section>
<script src="build.js"></script>
<script>
require('./client/boot')
</script>
</body>
</html>
也許HtmlUnit不理解JavaScript。 – immibis 2015-03-25 06:47:48