[英]how to collect a particular row id's in an table - webdriver using java collections
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>
我想收集所有沒有樣式屬性值的tr id,
預期的輸出,
“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);
}
}
查找沒有某些屬性的元素的問題在此得到解決:
https://stackoverflow.com/a/18774549/2131257
並找到所有元件S采用的方法
driver.findElements(By.id("element_id"))
返回元素列表而不是
driver.findElement(By.id("element_id"))
僅返回一個元素。
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.