简体   繁体   English

如何检查表上的特定TD是否包含我想要的值?

[英]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来找到值为3td

'//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.

相关问题 如何检查 ArrayList 是否包含具有特定字段值的对象? - How can I check if an ArrayList contains an Object with a specific field value? 如何检查一组对象是否包含 object,该 object 的特定字段在 Java 中有特定值? - How can I check if a Set of objects contains an object having a specific fields with a specific value in Java? 我想在td中放置一个动态值,在表中有很多td,但是我想将值放在特定的td中 - I want to place a dynamic value in a td , in a table there haave a so many td, but I want to place the value in a particular td 在Java中,如何检查集合是否包含特定类的实例? - In Java, how can I check if a collection contains an instance of a specific class? 如何从arrayList中删除特定对象,以及如何检查其中是否包含该对象? - How can I remove a specific object from an arrayList and how can I check if it contains this object? 如何检查字符串是否包含(数字) - How can I check if a string contains (number) 我想检查一列是否在实体对象列表中具有特定值。我该怎么做? - I want to check if a column has specific values in list of entity objects.?How can i do that? 我想检查一个字符串是否包含重复超过三次的特定字符 - I want to check whether a string contains specific characters repeated more than thrice 如何检查任何 arraylist 是否包含特定字符串 - How do I check if any arraylist contains specific string 我想访问表中嵌套 td 的内容 - I want to access contents of a nested td within a table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM