I am using Selenium Server (v2.21) and Selenium Java Client (v.2.21.0) to automate a web form that needs to have the Enter key pressed after each entry, since fields are exposed based on the value entered. So based on the solution here, I've been trying different ways to enter a string into the form and press Enter - here are the ones that I've tried:
// type field value
selenium.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");
It would seem like this is the most logical solution (selenium.keyPressNative(Keys.ENTER)
), but the compiler throws an error if you don't add the .toString
, since keyPressNative
is expecting a String.
The actual form code:
<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>
How do I emulate the press of the Enter key?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…