在Selenium脚本中按Enter键
我正在使用Selenium Server(v2.21)和SeleniumJavaClient(v.2.21.0)来自动化Web表单,该表单需要Enter
在每次输入后都按下键,因为字段是根据输入的值公开的。因此,根据此处的解决方案,我一直在尝试不同的方法以在表单中输入字符串并按Enter
-这是我尝试过的方法:
// type field valueselenium.type("program", "MIC HOMEOWNERS");
// ** not working: selenium.keyPress("program", "\\13");
// ** not working: selenium.select("program", "Program");
// ** not working: selenium.keyPressNative(Keys.ENTER.toString());
// ** not working: selenium.keyDown("program", "13");
它会 看起来
像这是最合理的解决方案(selenium.keyPressNative(Keys.ENTER)
),但是编译器抛出,如果你不添加一个错误.toString
,因为keyPressNative
期待一个字符串。
实际的表单代码:
<label >Program</label> <input id="program" name="program1" class="readonly-bg" readonly="readonly" type="text" value="MIC HOMEOWNERS" size="12"/>
<input id="program" name="program" type="hidden" value="601"/>
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "program",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : {
trim:true ,
required : true
}}));
</script>
<br>
如何模拟按键的Enter
按下?
回答:
我正在使用以下代码单击 或 。
try { Thread.sleep(700);
} catch (InterruptedException e) {
selenium.keyPressNative("27"); // Escape
selenium.keyPressNative("10"); // Enter
}
我们需要暂停硒直到成功执行上一个命令。所以我正在使用sleep()方法。对于我的测试用例,我需要暂停700 MillSec。根据您的要求,您需要更改值。
以上是 在Selenium脚本中按Enter键 的全部内容, 来源链接: utcz.com/qa/434734.html