我自动化的用户界面使用div标签。它为表的所有迭代显示相同的文本。请找到HTML代码和我的脚本。请帮忙。
<div class="panelbody"/>
<div class="hdrInv"
<div class="STable">
<div class="sitezones">
<div class="row">
<div class="col">
<b> Text1</b>
</div>
<div class="hdrInv"
<div class="STable">
<div class="sitezones">
<div class="row">
<div class="col">
<b> Text2</b>
</div>
<div class="hdrInv"
<div class="STable">
<div class="sitezones">
<div class="row">
<div class="col">
<b> Text3</b>
</div>
</div>
Webdriver代码
List<WebElement> table = driver.findElements(By.xpath("//div[contains(@class,'hdrInv')]"));
System.out.println("No of Tables: "+table.size());
for(int tabind=0;tabind<table.size(); tabind++){
System.out.println("ROWText: "+table.get(tabind).findElement(By.xpath("//div[1]/div[contains(@class,'site-zones')]/div[@class='row']/div[2]")).getText());
}
显示, ROWText:Text1 ROWText:Text1 ROWText:Text1
答案 0 :(得分:0)
您可以尝试以下代码。
List<WebElement> table = driver.findElements(By.xpath("//div[contains(@class,'hdrInv')]"));
System.out.println("No of Tables: "+table.size());
for(int tabind=0;tabind<table.size();tabind++)
{
System.out.println("ROWText: "+table.get(tabind).findElement(By.xpath(".//div[1]/div[contains(@class,'site-zones')]/div[@class='row']/div/b")).getText());
}
答案 1 :(得分:0)
以下可能会工作,但尚未测试过。
您需要使用$date1=date_create("2017-02-01");
$date2=date_create("2017-04-01");
$diff=date_diff($date1,$date2);
$res = $diff->format("%R%a days");
echo ($res + 2);
或.//
来查找相对元素,否则我猜它会从开头找到元素,./
html
答案 2 :(得分:0)
我找到了解决方案:
List <WebElement> rows = driver.findElements(By.xpath("//div[contains(@class,'STable')]/div/div[@class='row']"));
for(WebElement row:rows)
{
System.out.println("Text "+row.findElement(By.xpath("div[2]")).getText());
}