我使用Selenium Server(v2.21)和Selenium Java Client(v.2.21.0)来自动化每个条目后需要按下Enter键的Web表单,因为字段是根据输入的值公开的.因此,基于解决方案
here,我一直在尝试不同的方式在表单中输入字符串并按Enter键 – 这是我尝试过的:
// 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");
看起来这是最合乎逻辑的解决方案(selenium.keyPressNative(Keys.ENTER)),但如果不添加.toString,编译器会抛出错误,因为keyPressNative需要一个String.
实际的表单代码:
Program
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "program",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : {
trim:true ,
required : true
}}));
如何模拟按Enter键?