5

I'm having an issue with trying to click a hidden element in a Protractor test.

Below is the error message that is being returned, as well the code snippet that is causing the error message. Any idea as to why this error is being thrown would be greatly appreciated.

RangeError: Maximum call stack size exceeded


browser.driver.executeScript("return arguments[0].click()", bank_page.boaClick);

And "bank_page.boaClick()" is referenced as a variable on a page Object with the snippet seen below:

 boaClick: { get: function () { return element.all(by.model('bankConnection.bank')).get(0); }},

And below is the snippet that I am attempting to reference with that variable:

<input type="radio" ng-model="bankConnection.bank" ng-value="bank" class="ng-valid ng-dirty" name="00D" value="[object Object]">

I basically just want to be able to click this radio button, but the button is a hidden element, so after searching online that first "browser.driver.executeScript" call seems to be the best option to achieve this, but I am getting the RangeError back since I have implemented it.

parchambeau
  • 1,141
  • 9
  • 34
  • 56

1 Answers1

6

executeScript does not take a page object. You need to pass in a raw web_element. (Protractor's element finder does not work either)

Try:

browser.driver.executeScript("return arguments[0].click()", bank_page.boaClick.get().getWebElement());
hankduan
  • 5,994
  • 1
  • 29
  • 43
  • Thank you for the help, this seems to make it so the "RangeError" is no longer present, but I am still having an issue where it is not actually clicking the hidden element. Any ideas? – parchambeau Jan 27 '15 at 22:33
  • Check that you're selecting the right element. Does `element.all(by.model('bankConnection.bank')).get(0).getAttribute('name')).toEqual('00D')` work? – hankduan Jan 28 '15 at 00:24
  • If I add in the following: expect(element.all(by.model('bankConnection.bank')).get(0).getAttribute('name')).toEqual('00D'); I get back an error saying that " Expected '011' to equal '00D'." so it is definetly finding something at that location. – parchambeau Jan 28 '15 at 02:09
  • Rather, it is not finding the name="00D" – parchambeau Jan 28 '15 at 02:17
  • I also tried running this: element.all(by.repeater('bank in firstBanks')).then(function(banks) { var bankElement = banks[0].element(by.model('bankConnection.bank')); expect(bankElement.getAttribute('name')).toEqual('00D'); }); And I'm also getting the same "011" returned instead of "00D" – parchambeau Jan 28 '15 at 03:18
  • You might have duplicated data somewhere. Try `element.all(by.model('bankConnection.bank')).getAttribute('name').then(function(res) {console.log('res:', res)})` and see what you get – hankduan Jan 28 '15 at 05:45
  • Ended up being that in chrome developer tools a "name=00D" was being inserted, when it was not in my actual file. – parchambeau Jan 28 '15 at 08:34
  • Just wanted to say, "Thank You, Thank You, Thank You!"...OMG, this RangeError has been plaguing me for so long. So glad I found your post here. – Joe Famme Jun 10 '16 at 16:21