java - Selenium webdriver iterate through rows and retrieve only certain columns -
i have tbody
multiple tr
s , 10 td
s per tr
.
i want iterate through tr
s , .text()
of specific td
s. below section itterate throught tr
s have been assigned list
(alertstablerowslist
)
for (int = 0; < alertstablerowscount; i++){ string reference = alertstablerowslist.get(i).findelement(by.xpath("//td[@data-title-text = 'reference']")).gettext(); //td number 3 string classification = alertstablerowslist.get(i).findelement(by.xpath("//td[@data-title-text = 'classification']")).gettext(); //td number 4 string description = alertstablerowslist.get(i).findelement(by.xpath("//td[@data-title-text = 'description']")).gettext(); //td number 7 string status = alertstablerowslist.get(i).findelement(by.xpath("//td[@data-title-text = 'status']")).gettext(); //td number 8 string date = alertstablerowslist.get(i).findelement(by.xpath("//td[@data-title-text = 'date']")).gettext(); //td number 9 string owner = alertstablerowslist.get(i).findelement(by.xpath("//td[@data-title-text = 'owner']")).gettext(); //td number 10 system.out.println("reference : " + reference); system.out.println("classification : " + classification); system.out.println("description : " + description); system.out.println("status : " + status); system.out.println("date : " + date); system.out.println("owner : " + owner); }
what notice .text()
of td
s in first tr
returned. in case returned twice because in case have 2 tr
s in tbody
.
output:
reference : aml_ac.20161102.12 classification : aml central alert wholesale - wire transfer description : thoughtbeat ltd status : analysis date : 11/02/2016 owner : strydom, aj (rico) reference : aml_ac.20161102.12 classification : aml central alert wholesale - wire transfer description : thoughtbeat ltd status : analysis date : 11/02/2016 owner : strydom, aj (rico)
html tbody:
<tbody> <!-- ngrepeat: searchresult in $data --> <tr ng-repeat="searchresult in $data" ng-click="vm.clickentity(searchresult)" ng-dblclick="vm.dblclickentity()" ng-class="{ 'is-selected': vm.isentityselected(searchresult.id) }" class="pointer ng-scope" title="thoughtbeat ltd"> <!-- ngif: core.user.can('webhq.home.assign') --> <td data-title="''" class="table-icon-cell ng-scope" ng-if="core.user.can('webhq.home.assign')" ng-click="$event.stoppropagation()" header="vm.checkboxtemplate" data-title-text=""> <!-- ngif: vm.iseditable(searchresult) --> <div class="checkbox ng-scope" ng-if="vm.iseditable(searchresult)"><label><input type="checkbox" ng-model="vm.checkedentities[searchresult.id]" ng-change="vm.entitychecked()" class="ng-pristine ng-untouched ng-valid ng-empty"> <span class="checkbox-label"></span></label></div> <!-- end ngif: vm.iseditable(searchresult) --> </td> <!-- end ngif: core.user.can('webhq.home.assign') --> <td data-title="'*'" sortable="'attentionicon'" class="table-icon-cell" data-title-text="*"><img bf-image-path="" class="table-icon" src="/assets/img/icons/_blank.png"></td> <td data-title="'home.reference' | translate" sortable="'reference'" data-title-text="reference" class="ng-binding">aml_ac.20161102.12</td> <td data-title="'home.classification' | translate" sortable="'classification.id'" data-title-text="classification" class="ng-binding"> <img bf-image-path="writtentransfer" class="table-icon" src="/assets/img/icons/writtentransfer.png"> aml central alert <!-- ngif: ::searchresult.variation.displayname --><small class="text-muted ng-binding ng-scope" ng-if="::searchresult.variation.displayname"><br><img bf-image-path="'_blank'" class="table-icon" src="/assets/img/icons/_blank.png"> wholesale - wire transfer</small><!-- end ngif: ::searchresult.variation.displayname --> </td> <td data-title="'*'" sortable="'attachmentcount'" class="table-icon-cell" data-title-text="*"><img bf-image-path="_blank" class="table-icon" title="0 files attached" src="/assets/img/icons/_blank.png"></td> <td data-title="'*'" sortable="'notescount'" class="table-icon-cell" data-title-text="*"><img bf-image-path="_blank" class="table-icon" title="0 notes" src="/assets/img/icons/_blank.png"></td> <td data-title="'home.name' | translate" sortable="'displayname'" data-title-text="description"><img bf-image-path="priority_normal" class="table-icon" src="/assets/img/icons/priority_normal.png"> <strong class="ng-binding">thoughtbeat ltd</strong></td> <td data-title="'home.status' | translate" sortable="'status.progress'" data-title-text="status"><img bf-image-path="microscope" class="table-icon" src="/assets/img/icons/microscope.png"> <span ng-class="{ 'text-danger': searchresult.status.attract }" class="ng-binding">analysis</span></td> <td data-title="'home.date' | translate" sortable="'startdate'" data-title-text="date"><span ng-hide="searchresult.isdue" class="ng-binding">11/02/2016</span> <span ng-show="searchresult.isdue" class="text-danger ng-hide"><strong class="ng-binding">due in 2 days</strong></span></td> <td data-title="'home.owner' | translate" sortable="'ownername'" data-title-text="owner" class="ng-binding"> strydom, aj (rico) <!-- ngif: ::searchresult.teamname --><small ng-if="::searchresult.teamname" class="text-muted ng-binding ng-scope"><br>test role</small><!-- end ngif: ::searchresult.teamname --> </td> </tr> <!-- end ngrepeat: searchresult in $data --> <tr ng-repeat="searchresult in $data" ng-click="vm.clickentity(searchresult)" ng-dblclick="vm.dblclickentity()" ng-class="{ 'is-selected': vm.isentityselected(searchresult.id) }" class="pointer ng-scope" title="skiba ltd"> <!-- ngif: core.user.can('webhq.home.assign') --> <td data-title="''" class="table-icon-cell ng-scope" ng-if="core.user.can('webhq.home.assign')" ng-click="$event.stoppropagation()" header="vm.checkboxtemplate" data-title-text=""> <!-- ngif: vm.iseditable(searchresult) --> <div class="checkbox ng-scope" ng-if="vm.iseditable(searchresult)"><label><input type="checkbox" ng-model="vm.checkedentities[searchresult.id]" ng-change="vm.entitychecked()" class="ng-pristine ng-untouched ng-valid ng-empty"> <span class="checkbox-label"></span></label></div> <!-- end ngif: vm.iseditable(searchresult) --> </td> <!-- end ngif: core.user.can('webhq.home.assign') --> <td data-title="'*'" sortable="'attentionicon'" class="table-icon-cell" data-title-text="*"><img bf-image-path="" class="table-icon" src="/assets/img/icons/_blank.png"></td> <td data-title="'home.reference' | translate" sortable="'reference'" data-title-text="reference" class="ng-binding">aml_ac.20161102.9</td> <td data-title="'home.classification' | translate" sortable="'classification.id'" data-title-text="classification" class="ng-binding"> <img bf-image-path="writtentransfer" class="table-icon" src="/assets/img/icons/writtentransfer.png"> aml central alert <!-- ngif: ::searchresult.variation.displayname --><small class="text-muted ng-binding ng-scope" ng-if="::searchresult.variation.displayname"><br><img bf-image-path="'_blank'" class="table-icon" src="/assets/img/icons/_blank.png"> private banking - wire transfer</small><!-- end ngif: ::searchresult.variation.displayname --> </td> <td data-title="'*'" sortable="'attachmentcount'" class="table-icon-cell" data-title-text="*"><img bf-image-path="_blank" class="table-icon" title="0 files attached" src="/assets/img/icons/_blank.png"></td> <td data-title="'*'" sortable="'notescount'" class="table-icon-cell" data-title-text="*"><img bf-image-path="_blank" class="table-icon" title="0 notes" src="/assets/img/icons/_blank.png"></td> <td data-title="'home.name' | translate" sortable="'displayname'" data-title-text="description"><img bf-image-path="priority_normal" class="table-icon" src="/assets/img/icons/priority_normal.png"> <strong class="ng-binding">skiba ltd</strong></td> <td data-title="'home.status' | translate" sortable="'status.progress'" data-title-text="status"><img bf-image-path="microscope" class="table-icon" src="/assets/img/icons/microscope.png"> <span ng-class="{ 'text-danger': searchresult.status.attract }" class="ng-binding">analysis</span></td> <td data-title="'home.date' | translate" sortable="'startdate'" data-title-text="date"><span ng-hide="searchresult.isdue" class="ng-binding">11/02/2016</span> <span ng-show="searchresult.isdue" class="text-danger ng-hide"><strong class="ng-binding">due in 3 days</strong></span></td> <td data-title="'home.owner' | translate" sortable="'ownername'" data-title-text="owner" class="ng-binding"> strydom, aj (rico) <!-- ngif: ::searchresult.teamname --><small ng-if="::searchresult.teamname" class="text-muted ng-binding ng-scope"><br>test role</small><!-- end ngif: ::searchresult.teamname --> </td> </tr> <!-- end ngrepeat: searchresult in $data --> </tbody>
if alertstablerowslist list of webelements iterate this:
(int = 0; < alertstablerowslist.size(); i++){ string reference = driver.findelement(by.xpath("//tbody/tr[" + (i + 1) + "]/td[@data-title-text = 'reference']")).gettext(); string classification = driver.findelement(by.xpath("//tbody/tr[" + (i + 1) + "]/td[@data-title-text = 'classification']")).gettext(); //td number 4 string description = driver.findelement(by.xpath("//tbody/tr[" + (i + 1) + "]/td[@data-title-text = 'description']")).gettext(); //td number 7 string status = driver.findelement(by.xpath("//tbody/tr[" + (i + 1) + "]/td[@data-title-text = 'status']")).gettext(); //td number 8 string date = driver.findelement(by.xpath("//tbody/tr[" + (i + 1) + "]/td[@data-title-text = 'date']")).gettext(); //td number 9 string owner = driver.findelement(by.xpath("//tbody/tr[" + (i + 1) + "]/td[@data-title-text = 'owner']")).gettext(); //td number 10 system.out.println("reference : " + reference); system.out.println("classification : " + classification); system.out.println("description : " + description); system.out.println("status : " + status); system.out.println("date : " + date); system.out.println("owner : " + owner); }
Comments
Post a Comment