Protractor: how to click all the delete buttons in a page object

I have a table with 3 rows of data and 3 delete buttons. I want to delete all rows of data, so I'm trying to write a method in my page object to do this ... this should be fast, but I can't get it to work. I try it like this:

this.rows = element.all(by.repeater('row in rows')); this.deleteAllFriends = function() { this.rows.each(function(row) { row.$('i.icon-trash').click(); }) }; 

But this causes an error:

 Error: Index out of bound. Trying to access index:2, but locator: by.repeater("row in rows") only has 1 elements 

Thus, it is obvious that the protractor pointer expects the next one; it no longer exists because it has been deleted. How can I get around this?

This also does not work and produces the same error:

 this.deleteButtons = $$('i.icon-trash'); this.deleteAllFriends = function() { this.deleteButtons.each(function(button) { button.click(); }); }; 

This also does not work ...

 this.deleteAllFriends = function() { while(this.deleteButton.isDisplayed()) { this.deleteButton.click(); } }; 
+6
source share
2 answers

Today version> = 1.3.0 of the Protractor now you can do it right away

 $$('i.icon-trash').click(); 

feat (protractor): enable advanced features for ElementArrayFinder

+8
source

I finally figured it out ...

 this.deleteButtons = $$('i.icon-trash'); // locator this.deleteAllFriends = function() { var buttons = this.deleteButtons; buttons.count().then(function(count) { while(count > 0) { buttons.first().click(); count--; } }) }; 
+2
source

Source: https://habr.com/ru/post/975436/


All Articles