sendKeys不工作IE

时间:2013-10-21 15:28:11

标签: java selenium-webdriver testng

我在网站上有三个字段,我用joda时间填充。在Firefox中一切正常。但是,在IE中,IRB到期日期字段将填充“开始日期”和“结束日期”字段未填充。有什么想法吗?这是IE9。我已经更新到joda时间的最新版本,我仍然没有快乐。我已将WebDriver和IEDriver更新为2.37。我将它发送到控制台时正确输出时间。

//Enter an IRB Expiration Date - This is the one which works
WebElement irbExpCP = driver.findElement(By.id("irbExpDate"));
irbExpCP.click();
LocalDate irbDate = LocalDate.now().plusYears(5);
DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd/yyyy");
String irbDate2 = formatter.print(irbDate);
irbExpCP.sendKeys(irbDate2);

//Enter a Start Date
WebElement startDateCP = driver.findElement(By.id("startDate"));
startDateCP.click();
LocalDate startDate = LocalDate.now();
String startDate2 = formatter.print(startDate);
startDateCP.sendKeys(startDate2);

//Enter an End Date
WebElement endDateCP = driver.findElement(By.id("endDate"));
endDateCP.click();
LocalDate endDate = LocalDate.now().plusYears(10);
String endDate2 = formatter.print(endDate);
endDateCP.sendKeys(endDate2);

2 个答案:

答案 0 :(得分:2)

解决方案Actions Class方法尝试使用sendKeys()

Actions action = new Actions(driver);
action.sendKeys(yourElement, textToEnter).build().perform();

注意:在IE中,大多数sendsKeys()随机打印一半或单个字符。通过上述解决方案,我们可以解决这个问题。

答案 1 :(得分:0)

我可以想到两种情况:

1.确保您能够选择专注于元素。     有时您可能需要在输入元素之前关注元素。 所以尽量把重点放在元素上 使用这种方法(只是一个例子)

    driver.findElement(By.id("myid")).click();
    driver.findElement(By.id("myid")).sendKeys("text");

如果是这种情况,这应该可以正常工作。

2.)其他情况我应该归功于IEDriver架构。我有core i5并正在IEDriver尝试64 bit,这导致了一些问题,(例如sendkeys在下一封信之前3-4秒左右工作非常缓慢)。因此,如果是这种情况,请尝试更改IEDriver