[英]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.