简体   繁体   English

如何在表格中收集特定的行ID-使用Java集合的WebDriver

[英]how to collect a particular row id's in an table - webdriver using java collections

Html code HTML代码

<table id="tblRenewalsStatus" class="bor-bot" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr id="trVerifyPayment">
<tr id="trAssignAgent">
<tr id="trAssigned">
<tr id="trPayAgent" style="display: none;">
<tr id="trPaymentVerificationPending" style="display: none;">
<tr id="trInProgress" style="display: none;">
<tr id="trPayAgentCommission">
<tr id="trPaymentVerificationPendingCommission">
<tr id="trCompleted">
<tr id="trCancelled">
</tbody>
</table>

I want to collect all the tr id's which don't have an style Attribute value in it, 我想收集所有没有样式属性值的tr id,

Expected output, 预期的输出,

"trVerifyPayment","trAssignAgent","trAssigned",trPayAgentCommission","trPaymentVerificationPendingCommission","trCompleted","trCancelled" “trVerifyPayment”, “trAssignAgent”, “trAssigned”,trPayAgentCommission”, “trPaymentVerificationPendingCommission”, “trCompleted”, “trCancelled”

List<WebElement> id_elements = driver.findElements(By.xpath("//table[@id='tblRenewalsStatus']//tr"));

    ArrayList<String> tr_id= new ArrayList<String>();
    for(WebElement ele : id_elements)
     {

        String style = ele.getAttribute("style");

        if(style==null||style=="")
        {
            String id=ele.getAttribute("id");
            tr_id.add(id);
        }
      }

    System.out.println(tr_id);
WebElement RenewalTable = driver
                .findElement(By.id("tblRenewalsStatus"));
        List<WebElement> allRows = RenewalTable.findElements(By.tagName("tr"));
        ArrayList<String> enableRow = new ArrayList<String>();
        for (WebElement eachElement : allRows) {

            String style = eachElement.getAttribute("style");

            if (style.equals("")) {
                String id = eachElement.getAttribute("id");
                enableRow.add(id);
            }
        }

problem about finding element without some attribute is solved here: 查找没有某些属性的元素的问题在此得到解决:

https://stackoverflow.com/a/18774549/2131257 https://stackoverflow.com/a/18774549/2131257

and for find all element s is used method 并找到所有元件S采用的方法

driver.findElements(By.id("element_id")) 

which return list of elements instead of 返回元素列表而不是

driver.findElement(By.id("element_id"))

which return only one element. 仅返回一个元素。

Hope it helps. 希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收集表内的所有div ID-使用Java的Webdriver - Collect all the div id inside the table - webdriver using Java Selenium Webdriver Java:如何使用行号和列号单击表中的特定单元格 - Selenium Webdriver Java: How to click on a particular cell in table using row and column numbers 如何使用Selenium Webdriver Java查找表行号 - How to find the table row number using Selenium Webdriver Java 帧 ID 动态变化 - 如何使用 java 收集那些 id selenium webdriver - Frame ID dynamic changes - how can collect those id selenium webdriver with java 如何使用 Selenium Webdriver 和 Java 在同一行中单击旁边/上一个表格单元格(TD)? - How to click on the aside / previous Table Cell (TD) in the same row using Selenium Webdriver with Java? 是否有一个Java Stream方法等同于Scala的集合“collect”? - Is there a Java Stream method equivalent to Scala's collections “collect”? 如何使用Webdriver(Java)获取下一个随机生成的父ID - How to get the next randomly generated parent ID using Webdriver (Java) 如何遍历表以查找第 1 列中的字符串匹配项,然后使用 Selenium WebDriver Java 在另一列的同一行上选择下拉列表? - How to loop through table to find a string match in column 1, then select a dropdown on the same row in another column using Selenium WebDriver Java? 使用Java 8流收集到Guava的ListMultiMap中 - Collect into Guava's ListMultiMap using Java 8 streams 如何使用WebDriver和Java在日历表中找到链接? - How to locate links in a calendar table using webdriver and java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM