Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor - select next sibling of the current element

In my code there a list of elements (tr) selected with "protractor.By.repeater". This list is looped using "forEach".

Within this loop, the element is clicked, and this click should trigger the inclusion of a new "tr" just after the clicked element.

I want to select that new line.

I used :

var nextRow = tr.$(protractor.By.xpath('following-sibling::tr'));

but then with :

                nextRow.isDisplayed(function(row){
                    console.log('row', row);
                });

it generates errors such as : " UnknownError: java.util.HashMap cannot be cast to java.lang.String"

Is there another way to achieve what I want, i.e to select the next sibling of the current element ?

Or did I wrote something incorrect there ?

Thanks for any help!

like image 917
Olivvv Avatar asked Feb 12 '23 05:02

Olivvv


1 Answers

Looks like you are missing a .then there and misinterpreted what isDisplayed does.

Code should be more like:

nextRow.isDisplayed().then(function(visible) {
  console.log('is displayed? ', visible);
});

Also your ElementFinder nextRow doesn't look quite alright, what is variable tr below? and Protractor $ is an alias for element(by.css which takes a string argument, not a webdriver.Locator like you interpreted below, in your code:

var nextRow = tr.$(protractor.By.xpath('following-sibling::tr'));

So instead maybe you meant:

var tr = $('table tr.first'); // just guessing here since you didn't provide that code
var nextRow = tr.element(By.xpath('following-sibling::tr'));
like image 200
Leo Gallucci Avatar answered Feb 23 '23 14:02

Leo Gallucci