我有下表,我想验证"供应商分配已过期"介于"供应商接受的分配"和#34;供应商拒绝转让"。这样做最好的方法是什么?
<table cellspacing="0" cellpadding="0" border="0" style="table-layout: fixed; width: 100%; visibility: inherit;" id="x:1011327536.4:mkr:dataTbl.hdn" mkr="dataTbl.hdn">
<tbody id="x:1011327536.12:mkr:rows:nw:1" class="ig_ListItem igg_ListItem" nw="1" mkr="rows">
<tr id="x:1011327536.13:adr:0:tag:" tag="" adr="0" type="row">
<td class="grdCell" style="width:46%;" idx="0" adr="0" type="cell"> Update Disclosure Date </td>
</tr>
<!--[600001]-->
<tr id="x:1011327536.13:adr:1:tag:" class="ig_ListAlt igg_ListAlt" tag="" adr="1" type="row">
<td class="grdCell" idx="0" adr="0" type="cell"> Vendor Accepted Assignment </td>
</tr>
<!--[101020]-->
<tr id="x:1011327536.13:adr:2:tag:" tag="" adr="2" type="row">
<td class="grdCell" idx="0" adr="0" type="cell"> Vendor Assignment Expired </td>
</tr>
<!--[900101]-->
<tr id="x:1011327536.13:adr:3:tag:" class="ig_ListAlt igg_ListAlt" tag="" adr="3" type="row">
<td class="grdCell" idx="0" adr="0" type="cell"> Vendor Declined Assignment </td>
</tr>
<!--[900102]-->
<tr id="x:1011327536.13:adr:4:tag:" tag="" adr="4" type="row">
<td class="grdCell" idx="0" adr="0" type="cell"> Conditionally Declined </td>
</tr>
&#13;
我知道我可以像这样遍历每个项目:
List<WebElement> row = getDriver().findElements(By.cssSelector(".igg_ListItem > tr > td:nth-child(1)"));
for(WebElement el : row)
{
el.getText();
}
我只是不确定如何捕获值来执行文本在其他2之间显示的断言。
答案 0 :(得分:3)
你可以试试这个 -
List<WebElement> row = getDriver().findElements(By.cssSelector(".igg_ListItem > tr > td:nth-child(1)"));
for (int i =0; i<row.size();i++) {
String status = row.get(i).getText();
if (status.equalsIgnoreCase("Vendor Assignment Expired")) {
if (row.get(i-1).getText().equalsIgnoreCase("Vendor Accepted Assignment")
&& row.get(i+1).getText().equalsIgnoreCase("Vendor Declined Assignment"))
System.out.println("Yes it between those values");
break;
}
}
让我知道它是否有效!干杯!
答案 1 :(得分:2)
您可以使用以下内容:
获取下一列Text并使用预期值断言。
String declinedAssignment = driver.findElement(By.xpath("//tr[td[text()=/"Vendor Assignment Expired/"]]//following-sibling::tr/td")).getText();
获取上一列Text并使用预期值断言。
String acceptedAssignment = driver.findElement(By.xpath("//tr[td[text()=/"Vendor Assignment Expired/"]]//preceding-sibling::tr/td")).getText();