简体   繁体   English

收集表内的所有div ID-使用Java的Webdriver

[英]Collect all the div id inside the table - webdriver using Java

Html Code HTML代码

<table id="tblRenewalAgent" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<div class="form-row">
<div id="trStatus" style="">
<div id="trFees" class="form-row" style="">
<div id="trFees1" class="form-row ctrl-column" style="">
<div id="trFilingReceipt" class="form-row" style="">
<div id="trComments" class="form-row" style="">
<div id="trContact" class="form-row" style="">
<div id="trEmail" class="form-row" style="">
<div id="trPhone" class="form-row" style="">
<div id="trCell" class="form-row" style="">
<div class="form-row">
<div class="form-row ctrl-column">
<div id="trAmountPaid">
<div id="trBalanceDue" class="form-row">
</td>
</tr>
</tbody>
</table>

Expected: 预期:

i want to collect all the div id and store it an array 我想收集所有的div ID并存储一个array

my java code i'm struggled in side that for loop 我的java代码在for循环方面很挣扎

public void gettingFee() {
        WebElement ptoFeeTable = driver.findElement(By.xpath("//*[@id='tblRenewalAgent']/tbody"));
        List<WebElement>allRows = ptoFeeTable.findElements(By.tagName("tr"));
        for (int i=0;i<=allRows.size();i++){

         //collect all the div id's

        }

collect the following id's and store it an array (trStatus,trFees,trFees1,trFilingReceipt etc.,) 收集以下ID并将其存储为数组(trStatus,trFees,trFees1,trFilingReceipt等)

Hope it works: 希望它能工作:

public void gettingFee() {
        List<String> allIds = new ArrayList<String>();
        WebElement tdElement = driver.findElement(By.xpath("//*[@id='tblRenewalAgent']/tbody/tr/td"));
        List<WebElement> allDivElements = tdElement.findElements(By.tagName("div"));
        for(int i = 0; i<allDivElements.size(); i++){
           try{
           String id = allDivElements.get(i).getAttribute("id");
           allIds.add(id );
           } catch(Exception e) {}
        }
}

Try this; 尝试这个;

 public void gettingFee() {
    List<WebElement> divList = driver.findElements(By.tagName("div"));
    List<String> idList = new ArrayList<String>();
    for (WebElement e : divList) {
        if(!e.getAttribute("id").isEmpty()) {
            String s = e.getAttribute("id");
            idList.add(s);
            System.out.println(s);
        }
    }

}

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

相关问题 如何在表格中收集特定的行ID-使用Java集合的WebDriver - how to collect a particular row id's in an table - webdriver using java collections 使用带有java的webdriver获取div id值 - getting div id value using webdriver with java 如何使用Selenium WebDriver在表的div标记中获取值 - How to get the value inside a div tag in a table using selenium webdriver 帧 ID 动态变化 - 如何使用 java 收集那些 id selenium webdriver - Frame ID dynamic changes - how can collect those id selenium webdriver with java Webdriver-使用Java获取div值 - Webdriver - getting div value using java WebDriver-在Div内滚动 - WebDriver - Scroll Inside a Div 带有 Java 的 WebDriver - 无法使用 Webdriver 获取所有文本 - WebDriver with Java - Not able to get all the text using Webdriver "java.lang.NoClassDefFoundError: com\/google\/common\/collect\/ImmutableMap 在 Java Selenium 中使用带有 Maven 依赖关系的 WebDriver" - java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap while using WebDriver with Maven Dependencies in Java Selenium 使用 Java 收集所有 VersionOne 资产及其所有属性 - Collect all VersionOne assets and all their attributes using Java 如何使用 Selenium WebDriver 选择 div id? - How can I select the div id using Selenium WebDriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM