[英]How to get all the span value with Selenium WebDriver using Java?
I am trying to get all the span value with class of wd4 for by following code: 我正在尝试通过以下代码获取wd4类的所有span值:
List <WebElement> we = driver.findElements(By.xpath("//ul[@class='lottery']/li/span"));
HTML : HTML:
<li data-id="20151105031XJ500wh0001" data-istrace="0" class="evenTr first">
<span class="wd1">2015-11-05 16:10:58</span>
<span class="wd5">3D福彩</span>
<span title="一码不定胆">一码不定胆</span>
<span class="wd2">2015302</span>
<span class="wd3">元</span>
<span class="grid-toggle" alt="号码详情:">
<div class="wrapbox">
<em alt="2">2</em>
</div>
</span>
<span class="wd4">1</span>
<span>¥2</span>
<span>¥0</span>
<span class="wd4">未开奖</span>
<span alt="开奖号码:"></span>
<span class="wd3">否</span>
</li>
Indeed the code i trying to implement , its getting null value. 确实,我尝试实现的代码获得空值。 Kindly advise
好心提醒
// Page elements : //页面元素:
<StartTag: span> xyz</EndTag: span>
You can try this: re-frame the xpath as : 您可以尝试以下操作:将xpath重新构建为:
//span[contains(.,'xyz')]//
final code will be : 最终代码为:
driver.findElement(By.xpath("//span[contains(.,'xyz')]").getText();
Try this: 尝试这个:
List<String> spanText= new ArrayList<String>();
List <WebElement> we = driver.findElements(By.xpath("//li[@class='evenTr']/span[@class='wd4']"));
for(WebElement w : we) {
spanText.add(w.getText());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.