简体   繁体   中英

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

Html code

<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,

Expected output,

"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

and for find all element s is used method

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM