我试图在文本字段中输入帐号,该字段在下面的HTML中给出。但是,当我调试时,输入的数字将被完全删除,有时只输入最后的数字,有时会失败。
<input id="consumerNonew" name="consumerNonew" type="text" countchar="" length="10" display="true" setvallocal="" value="940" maxlength="10" ng-blur="click($event,{s:"consumerNonew",e:"blur",p:"dewaPaymentInpForm"});" autocomplete="off" class=" validate is-invalid-input">
以下是代码。
public void dwshortname_and_Contract_number_is_entered() throws Throwable {
Thread.sleep(5000);
driver.findElement(By.id("consumerNamenew")).sendKeys("TestUser");
Thread.sleep(5000);
WebElement Accnumber= driver.findElement(By.id("consumerNonew"));
final int MAXIMUM_WAIT_TIME = 120;
final int MAX_STALE_ELEMENT_RETRIES = 10;
WebDriverWait wait = new WebDriverWait(driver, MAXIMUM_WAIT_TIME);
int retries = 0;
while (true)
{
try
{
wait.until(ExpectedConditions.elementToBeClickable(By.id("consumerNonew"))).click();
Accnumber.sendKeys("2012269940");
Accnumber.sendKeys(Keys.TAB);
break;
//
}
catch (StaleElementReferenceException e)
{
if (retries < MAX_STALE_ELEMENT_RETRIES)
{
retries++;
continue;
}
else
{
throw e;
}
}
}
}
答案 0 :(得分:0)
机器人类的示例代码:
Robot RoboKey = new Robot();
RoboKey.delay(2000);
RoboKey.keyPress(KeyEvent.VK_2);
RoboKey.keyPress(KeyEvent.VK_0);
RoboKey.keyPress(KeyEvent.VK_1);
。 。 。
等等!