简体   繁体   中英

Click link from popup

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;
    }

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.

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(); 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM