0

Getting a Failed: stale element reference: element is not attached to the page document error when I run my protractor test to check the text in a toast pop up message. I have tried element.all but so no avail:

My expect statement is

it('Delete toast pop up', function() {   
var EC = protractor.ExpectedConditions;
publisher_whitelist_page.deleteButtonClick();
browser.wait(EC.visibilityOf(element(by.className('toast-success toast ng-trigger ng-trigger-flyInOut'))),5000);
expect(element.all(by.className('toast-success toast ng-trigger ng-trigger-flyInOut')).getText()).toEqual('Ip address removed');

Any help or guidance would be greatly appreciated!

Thanks!

Kirsty

EDIT

Bit of further progress getting the different error of Failed: Cannot read property 'bind' of undefined

Shaped it into a page object class:

this.popupToastIP = function(){
element.all(by.className('toast-success toast ng-trigger ng-trigger-flyInOut')).then(function(){
element(by.className('toast-success toast ng-trigger ng-trigger-flyInOut')).getText();

});

and my expect:

browser.wait(EC.visibilityOf(publisher_whitelist_page.popupToastIP),5000);
expect(publisher_whitelist_page.popupToastIP.toEqual('Ip address removed'));  

again any advice would be appreciated at least it is finding it but can't read it!

Kirsty Meredith
  • 69
  • 1
  • 2
  • 8

1 Answers1

0

You can replace your two last lines with: browser.wait(EC.textToBePresentInElement(element(by.className('toast-success toast ng-trigger ng-trigger-flyInOut')), 'Ip address removed'), 5000);

Kacper
  • 1,201
  • 1
  • 9
  • 21
  • Still getting the same error: Failed: stale element reference: element is not attached to the page document (Session info: chrome=63.0.3239.84) – Kirsty Meredith Jan 04 '18 at 15:56
  • Try: `browser.waitForAngularEnabled(false);` before wait. – Kacper Jan 04 '18 at 16:00
  • Is this element blinking, or reloading? Another guess: replace `waitForAngular` with `browser.wait(EC.stalenessOf(element(by.className('toast-success toast ng-trigger ng-trigger-flyInOut'))),5000);` – Kacper Jan 04 '18 at 16:11
  • Nope not reloading or blinking got the following error with what you suggested - Failed: stale element reference: element is not attached to the page document – Kirsty Meredith Jan 04 '18 at 16:22
  • See my edit above - getting new error of not being able to read the bind – Kirsty Meredith Jan 04 '18 at 16:26
  • `bind` issue. See here: https://stackoverflow.com/a/36179354/6331748 and here: https://stackoverflow.com/a/29971548/6331748 – Kacper Jan 04 '18 at 21:33
  • No luck Kacper - have tried following advice of 2 different posts but no luck - still getting bind error. – Kirsty Meredith Jan 05 '18 at 09:35