最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to click OK in alert box using protractor - Stack Overflow

programmeradmin3浏览0评论

I am using AngularJS and I want to delete a link, in such cases, an alert box appears to confirm the delete.

I am trying to do e2e test using protractor, how do I confirm in an alert box?

I tried:

browser.switchTo().alert().accept()

but it doesn't seem to work.

Is there a provision in protractor for handling alert boxes?

I am using AngularJS and I want to delete a link, in such cases, an alert box appears to confirm the delete.

I am trying to do e2e test using protractor, how do I confirm in an alert box?

I tried:

browser.switchTo().alert().accept()

but it doesn't seem to work.

Is there a provision in protractor for handling alert boxes?

Share Improve this question edited Jul 28, 2015 at 14:04 alecxe 474k126 gold badges1.1k silver badges1.2k bronze badges asked Jul 28, 2015 at 4:49 Prateek ChoudhuryPrateek Choudhury 3023 gold badges8 silver badges21 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 6

try

browser.driver.get('URL');
browser.switchTo().alert().accept();

or

browser.ignoreSynchronization = true
browser.get('URL');
browser.switchTo().alert().accept();

or : browser.switchTo().alert() not working in protractor

Wait for alert to become present:

var EC = protractor.ExpectedConditions;
browser.wait(EC.alertIsPresent(), 5000, "Alert is not getting present :(")

Set up a promise to wait for the alert to be present:

function getAlertAndClose(element) {
    return element.click().then(function (alertText) {
        //Wait for alert to pop up
        browser.wait(function () {
            return browser.switchTo().alert().then(
                function () {return true;},
                function () {return false;}
            );
        }, 3000); // Wait timeout

        // Test alert is what you expect
        var popupAlert = browser.switchTo().alert();
        alertText = popupAlert.getText();
        expect(alertText).toMatch('Are you sure you want to delete this?');

        // Close alert
        popupAlert.dismiss();
    })
}

var saveButton = $('.saveBtn');
getAlertAndClose(saveButton);

This will work fine:

await browser.switchTo().alert().accept();

This thing is wroking fine i have tried it


 await browser.switchTo().alert().accept();
发布评论

评论列表(0)

  1. 暂无评论