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