我有一個日期字段有時會被Webdriver element.sendKeys()填寫,其他時候字段只會被跳過。 (使用Chromedriver 2.9)。Webdriver有時會跳過日期字段
元素定位信息:
<input id="dateOfBirth" type="date" class=" form-control " placeholder="">
用於輸入文本和代碼重新嘗試,如果失敗:
//Web element already verified present and visible before being passed into the method
public static void enterText(WebElement weElement, String textToEnter) {
System.out.println(" *Thread:" +Thread.currentThread().getId() +" INFO: EnteringText: " +textToEnter);
//weElement.click();
weElement.sendKeys(textToEnter);
String textEntered = weElement.getAttribute("value");
System.out.println(" *Thread:" +Thread.currentThread().getId() +" INFO: TextDisplayed is: "+ textEntered);
//continued
int iAttempts = 0;
while (iAttempts < 1) {
if(!textEntered.isEmpty())
break;
else{
System.out.println(" *Thread:" +Thread.currentThread().getId() +" ERROR: re-Attempting to enter text: "+ textToEnter);
//weElement.click();
weElement.sendKeys(textToEnter);
textEntered= weElement.getAttribute("value");
System.out.println(" *Thread:" +Thread.currentThread().getId() +" INFO: Element text after re-attempt: "+ textEntered);
iAttempts++;
}
}
}
控制檯輸出:
*Thread:10 Trying: com.xxx.pageobjects.IdentityPage.typeDOB
*Thread:10 INFO: Locator is: [data-model-attribute='dateOfBirth'] input
*Thread:10 INFO: EnteringText: 01/01/1981
*Thread:10 INFO: TextDisplayed is:
*Thread:10 ERROR: re-Attempting to enter text: 01/01/1981
*Thread:10 INFO: Element text after re-attempt:
沒有人有任何的想法至於爲什麼這隻發生在日期字段?如果失敗了,還有什麼想法可以提供更好的解決方法? 謝謝!
注:我的程序只適用於Chrome瀏覽器,所以我無法證實,如果這個問題在其他瀏覽器
嗯,這似乎是幫助。我會暫時關閉它,如果它再次擡起它醜陋的頭,它將重新開放。 – gorbysbm