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>
这是一个'input'元素,你应该使用'deliveryDate.getAttribute( “值”);' – alecxe
您的标记不包含ID为 “deliveryDate” 任何元素,它是“到期日” –