2017-01-03 45 views
0

試圖捕捉的WebElement文本有以下兩種方法的任何屬性,但都返回空字符串硒的getText沒有工作,HTML沒有包含文本

// Method 1 

d.findElement(By.id("deliveryDate")).getTex(); 

// Method 2 

WebElement deliveryDate = d.findElement(By.id("deliveryDate")); 

System.out.println((String) js.executeScript("return arguments[0].innerText;", deliveryDate)); 

要捕獲「THU 17年2月2日」

SS >>Screen Shot

<label class="fieldset" _ngcontent-nok-32=""> 
 
<span class="caption captionPrimary" _ngcontent-nok-32="">Expiry</span> 
 
<tp-datepicker _ngcontent-nok-32="" _nghost-nok-35=""> 
 
<input id="expiryDate" class="highlighted ng-dirty ng-valid ng-touched" type="text" _ngcontent-nok-32="" formcontrolname="expiryDate" required="" spellcheck="false" tabindex="103"/> 
 
<button _ngcontent-nok-35="" tabindex="-1"/> 
 
</tp-datepicker> 
 
<span class="tenorWrap" _ngcontent-nok-32=""> 
 
<!--template bindings={}--> 
 
<span class="tenor" _ngcontent-nok-32="">     1M    </span> 
 
</span> 
 
</label>

+0

這是一個'input'元素,你應該使用'deliveryDate.getAttribute( 「值」);' – alecxe

+0

您的標記不包含ID爲 「deliveryDate」 任何元素,它是「到期日」 –

回答

0

嘗試

WebElement expiryDate= d.findElement(By.id("expiryDate")); 
string text=expiryDate.getAttribute("value");