Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

html - 量角器中的表行计数始终返回1(Table row count in protractor returns one always)

 <table class="customGridTable" tabindex="0" xpath="1"> <thead> <tr> <th class="customGridHeader selectionHeader"> <input type="checkbox" class="selectAllItems"> </th> <th class="customGridHeader subgridExpandHeader nonResizable"> &nbsp; </th> <th class="customGridHeader editHeader nonResizable"> Edit </th> <th class="customGridHeader typeHeader nonResizable"> Type </th> <th class="customGridHeader customGridSortable" style="width: 25%" data-columnid="title"> <div> <span>Title</span> <span class="columnEdit ui-button-icon-primary ui-icon ui-icon-pencil"></span> </div> </th> <th class="customGridHeader customGridSortable" style="width: 25%" data-columnid="created"> <div> <span>Created On</span> </div> </th> <th class="customGridHeader customGridSortable" style="width: 25%" data-columnid="modified"> <div> <span>Modified On</span> </div> </th> <th class="customGridHeader customGridSortable" style="width: 25%" data-columnid="keywords"> <div> <span>Keywords</span> <span class="columnEdit ui-button-icon-primary ui-icon ui-icon-pencil"></span> </div> </th> <th class="fillHeader"></th></tr> </thead> <tbody> <tr class="SearchResultItemView customGridHighlight"><td class="customGridDataCell AlignCenter"> <input type="checkbox" class="selectedItem" title="Item 1" checked="checked"></td><td class="customGridDataCell"> </td><td data-cellid="title" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>Webinar_+Integrating+Your+Test+Automation+with+Jira</span> </div> </td><td data-cellid="created" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>02/08/2019 12:12 pm</span> </div> </td><td data-cellid="modified" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>25/11/2019 03:25 pm</span> </div> </td><td data-cellid="keywords" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span></span> </div> </td></tr><tr class="SearchResultItemView"><td class="customGridDataCell AlignCenter"> <input type="checkbox" class="selectedItem"></td><td class="customGridDataCell"> <span class="subgridExpand ui-icon ui-icon-triangle-1-e"></span> </td><td class="customGridDataCell"> <span class="editRow ui-icon ui-icon-pencil"></span> </td><td class="customGridDataCell"> <div class="item_type_icon document_icon pdf"></div></td><td data-cellid="title" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>US Exp Report</span> </div> </td><td data-cellid="created" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>20/11/2019 06:08 pm</span> </div> </td><td data-cellid="modified" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>26/11/2019 10:32 am</span> </div> </td><td data-cellid="keywords" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>EditedAgain</span> </div> </td></tr><tr class="SearchResultItemView"><td class="customGridDataCell AlignCenter"> <input type="checkbox" class="selectedItem"></td><td class="customGridDataCell"> <span class="subgridExpand ui-icon ui-icon-triangle-1-e"></span> </td><td class="customGridDataCell"> <span class="editRow ui-icon ui-icon-pencil"></span> </td><td class="customGridDataCell"> <div class="item_type_icon document_icon pdf"></div></td><td data-cellid="title" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>US Exp Report</span> </div> </td><td data-cellid="created" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>20/11/2019 06:11 pm</span> </div> </td><td data-cellid="modified" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>26/11/2019 10:34 am</span> </div> </td><td data-cellid="keywords" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>EditedAgain</span> </div> </td></tr><tr class="SearchResultItemView"><td class="customGridDataCell AlignCenter"> <input type="checkbox" class="selectedItem"></td><td class="customGridDataCell"> </td><td class="customGridDataCell"> <span class="editRow ui-icon ui-icon-pencil"></span> </td> <td data-cellid="keywords" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span></span> </div> </td></tr><tr class="SearchResultItemView"><td class="customGridDataCell AlignCenter"> <input type="checkbox" class="selectedItem"></td><td class="customGridDataCell"> </td><td class="customGridDataCell"> <span class="editRow ui-icon ui-icon-pencil"></span> </td><td class="customGridDataCell"> <div class="item_type_icon document_icon pdf"></div></td><td data-cellid="title" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>todaysssss</span> </div> </td><td data-cellid="created" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>28/08/2019 02:42 pm</span> </div> </td><td data-cellid="modified" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>20/09/2019 02:54 pm</span> </div> </td><td data-cellid="keywords" class="customGridDataCell customGridEditCell "> <div class="valueContainer"> <span>sample</span> </div> </td></tr><tr class="SearchResultItemView"><td class="customGridDataCell AlignCenter"> <input type="checkbox" class="selectedItem"></td></tr></tbody> </table> 

    async getRows(): Promise<ElementFinder[]> {
    return new Promise(async (resolve, reject) => {
      this.waitForPresence();
      await browser.sleep(this.gridTimeout);
      resolve(this.component.element(by.css("tbody")).all(by.css("tr")));
    });
  }
    async getRowCount() {
    let retVal = 0;
    await this.getRows().then(async rws => {
      retVal = rws.length;
    });
    return retVal;
  }

I have the above code to get row count, but I get 1 as the result all the time.

(我有上面的代码来获取行数,但是结果一直都是1。)

  ask by Shreyas Murali translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Why don't use the .count() method that protractor gives you?

(为什么不使用量角器为您提供的.count()方法?)
It looks like you want to count all the tr 's iside the <tbody> ?

(看来您想算出所有tr的同侧<tbody>吗?)

In that case, try the following:

(在这种情况下,请尝试以下操作:)

const tbody = element(by.css('tbody'));
const tbodyRows = tbody.all(by.css('tr'));

const getRowCount = async () => {
    let rowsCount = await tbodyRows.count();
    return rowsCount;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...