2014-04-11 3 views
0

Selenium Web Driver를 사용하여 특정 필드에 값 (null)이 있는지 확인할 수 있습니까?필드에 값이 없음을 확인하려면 어떻게합니까?

이것은 내가 지금까지 무엇을 가지고 :

WebDriverWait wait5 = new WebDriverWait(driver, 5); 
wait5.until(ExpectedConditions.elementToBeClickable(By.name("chargeId"))); 
+0

코드는 완전히 다른 것을하고 있습니다. 요소가 * clickable *이 될 때까지 기다립니다. 확인할 필드는 무엇입니까? – xyz

+2

'null' **은 값이없는 것과는 다릅니다 **. 그것은 어떤 요소입니까? 우리에게 HTML을 보여주세요. – Arran

답변

0
WebDriverWait wait5 = new WebDriverWait(driver, 5); 
WebElement charge = wait5.until(ExpectedConditions.elementToBeClickable(By.name("chargeId"))); 
boolean noChargeIdPresent = charge.getText().isEmpty(); 

이 당신이 필드가 비어 있는지 여부를 알려줍니다.

+1

아니요,'WebdriverWait'는'getText' 메소드를 가지고 있지 않습니다. 대신 WebElement를 사용하고 싶습니다. – xyz

+0

Lol, 좋은 지적입니다. 나는 그것을 완전히 비 췄다. : p 수정하기 위해 수정했습니다. – Jamey

0
WebDriverWait wait5 = new WebDriverWait(driver, 5); 
wait5.until(ExpectedConditions.elementToBeClickable(By.name("chargeId"))); 
if(wait5.findElement(By.name("chargeId")).getText().length() == 0) { 
     // =========== DO WHAT YOU WANT IF EMPTY============ 
} 
else { 
    //======== DO WHEN NOT EMPTY================== 
} 
관련 문제