0

I have problem with click on link from popup. After click on button, popup is displayed for about 3 sec:

<toast-container class="ng-tns-c12-31 ng-star-inserted">
<div class="toast-top-center" id="toast-container" style="position: fixed;">
  <!----><div class="toast toast-info ng-star-inserted ng-animating">
    <!----><div class="toast-close-button ng-tns-c12-31 ng-star-inserted" style="">×
    </div> 
    <!---->
    <div class="ng-tns-c12-31">
      <!----><span class="toast-message ng-star-inserted" style="">Section will removed. <a class="toast-link">Cancel</a></span>
      <!---->
    </div>             
  </div>
</div>
</toast-container>

I was trying to click "Cancel" by

element(by.partialLinkText('Cancel'))

and

var cancelLink = $('#toast-container a');
browser.executeScript("arguments[0].click();", cancelLink)

But the link wasn't clicked. I have no idea how to Assertion works ok on this popup

var toastMessageBox = $('#toast-container');
    this.assertClearSelectionToastMessage = function () {
        expect(toastMessageBox.$('span').getText()).toBe(toastText)
        return this;
    }
gagatek
  • 63
  • 2
  • 14

2 Answers2

0

The popup isn't loaded yet. The link is not visible, therefore it can't be clicked. You have to wait for the popup to appear.

It is possible for element to be clickable and clicking on element does nothing.

See: https://stackoverflow.com/a/21387564/1997776

@Jonny Leeds noted that:

A major thing to watch out for is whether a button is Enabled or not. You can still click them and nothing will fall over and the element is there but it is not ready to be clicked on so just doesnt do anything.

Aulis Ronkainen
  • 164
  • 2
  • 4
  • 12
  • not really, becouse before it (click cancel) i assert message from this popup, and it works ok. When I console.log this popup, then in console is displayed this message from this popup - "Section will removed. Cancel" I tryed to use expected condition, visibility, elementToBeClicable, but it not working – gagatek May 30 '18 at 08:05
  • By logic that means that "element(by.partialLinkText('Cancel'))" can't find the element. How about finding it some other way, like id? Can you locate links at all? If both don't work, it suggests that the click doesn't work. Can you click links at all? – Aulis Ronkainen May 30 '18 at 08:29
  • Manually I can click it with no problem. But in console durign the test i get "Message: Failed: stale element reference: element is not attached to the page document (Session info: chrome=67.0.3396.62) (Driver info: chromedriver=2.39.562737 (dba483cee6a5f15e2e2d73df16968ab10b38a2bf),platform=Linux 4.13.0-43-generic x86_64)" – gagatek May 30 '18 at 08:55
  • You need to find the element again for it not to be stale. – Aulis Ronkainen May 30 '18 at 09:06
  • But Im trying to find it again " this.clickCancel = function () { var asa = $('a.toast_link'); asa.click(); return this; }" – gagatek May 30 '18 at 09:21
  • How about clicking link element that is not in a popup? I presume that it works. The problem has something to do with the initialization or the loading of the element. – Aulis Ronkainen May 30 '18 at 09:24
  • I click them without any problem. I have no idea were is the problem – gagatek May 30 '18 at 09:32
0

Maybe you can try to force the click on the link using Webdriver Actions builder?

Something along the lines of: browser.wait(protractor.ExpectedConditions.visibilityOf(element(by.css('a.toast_link'))), 5000); driver.actions().click(element(by.css('a.toast_link'))).perform();

Problem with this is that it only works on desktop browsers - it's not implemented in Appium yet - so you might have to introduce some logic to do it differently if you're testing on mobile browsers as well.

RagnarOdin
  • 42
  • 1
  • 6
  • waiting for 'a.toast_link' timeouts, but waiting for '#toast-container' is ok, no errors. Clicking by actions returns error Failed: No element found using locator: By(css selector, a.toast_link) – gagatek May 30 '18 at 09:19
  • Can you try using the full selector for the element? i.e. `#toast-container > div > div:nth-child(2) > span > a` If that doesn't work, perhaps you can force a click on the xpath? `//*[@id="toast-container"]//a` – RagnarOdin May 30 '18 at 09:33