我想通过添加一个“待办事项”,然后按回车测试输入字段,因为没有提交按钮,但我不断收到“无法找到包含窗体的错误”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