[英]How can I check if the specific TD on a table contains the value i want?
Im new on this field, and i would like to ask how you guys do it if you are trying to check or assert on the table to be specific that contains "WaterBill" for example. 我是该字段的新手,如果您要检查或断言包含“ WaterBill”的特定表,我想问一下您是如何做到的。 In the module listview, I have column name "Bill Type" and i quick search a WaterBill and I am expecting to have the output WaterBill for all Bill Type column.
在模块列表视图中,我具有列名“ Bill Type”,并且我快速搜索了一个WaterBill,并且我希望所有Bill Type列都具有输出WaterBill。 How do I check if all the elements in the column Bill Type only contains WaterBill?
如何检查“帐单类型”列中的所有元素是否仅包含WaterBill? My xpath for example is
例如,我的xpath是
/html/body/div[1]/div/div[3]/div/div/div[1]/div/div[2]/div[2]/div/div[3]/div/table/tbody/tr[1]/td[1]
Note: Every Bill Type on the listview has different TR and in every TR the specific Waterbill is always on the TD[2] 注意:列表视图上的每个账单类型都有不同的TR,在每个TR中,特定的Waterbill始终位于TD [2]上
lets say you have table 假设您有桌子
<table border="1" >
<tr>
<td>Table Cell</td>
<td>Waterbill</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Waterbill</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>3</td>
<td>Table Cell</td>
</tr>
</table>
you can have an xpath to find td
with value 3
by following xpath 您可以通过遵循xpath的xpath来找到值为
3
的td
'//table/descendant-or-self::td[contains(text(),"3")]'
if your table has id you can filter that out by 如果您的表有ID,则可以通过
'//table[@id="xyz"]/descendant-or-self::td[contains(text(),"3")]'
for selecting nth column you would do sth like this 选择第n列,你会做这样的
'//table[@border=1]/descendant-or-self::tr/child::td[position()=4 and contains(text(),"3")]'
in your specific case xpath will be 在您的特定情况下,xpath将是
'//table[@border=1]/descendant-or-self::tr/child::td[position()=2 and contains(text(),"Waterbill")]'
*note 2nd row /3rd column will not be selected *注意不会选择第二行/第三列
int count=obj.findElements(By.xpath("/html/body/div[1]/div/div[3]/div/div/div[1]/div/div[2]/div[2]/div/div[3]/div/table/tbody/tr")).size(); int count = obj.findElements(By.xpath(“ / html / body / div [1] / div / div [3] / div / div / div [1] / div / div [2] / div [2] / 。DIV / DIV [3] / DIV /表/ tbody的/ TR“))尺寸(); //get the count of no.
//得到no的计数 of rows in the table
表中的行数
for(int i=0;i<=count;i++) //loop as per the count of table
{
String a=obj.findElement(By.xpath("/html/body/div[1]/div/div[3]/div/div/div[1]/div/div[2]/div[2]/div/div[3]/div/table/tbody/tr["+i+"]/td[2]")).getText(); //Retrieving the data from the Td of table in to a string
if(a.contains("WaterBill"))
{
System.out.println("contains WaterBill");
}
else
{
System.out.println("does not contains WaterBill");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.