Handling Angular JS prompt/dialog box in webpage

70 views
Skip to first unread message

Vivek Rao

unread,
Jul 10, 2017, 1:56:23 AM7/10/17
to Selenium Users

I have an angularjs webpage that prompts when I perform certain action on the page. The code should ignore and continue if there is no prompt, but if a prompt appears then ensure that the javascript prompt is accepted.

When I use firebug, I get the following property of the element. /html/body/div[2]


The div[number] changes as and when I go to this page.I am not able to use the same in XPath as everytime the test case is executed, the div element would change. Also the div has an attribute of tabindex = -1.

 bool status = false;
        WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));
        IWebElement alert;

        if (wait.Until(ExpectedConditions.InvisibilityOfElementLocated((By.XPath("/html/body/div[2]")
        {
            Console.WriteLine("I am in if loop");
            status = false;
        }
        else
        {
            Console.WriteLine("I am in else loop");
            alert = Browser.Driver.FindElement(By.XPath("/html/body/div[2]"));
            ((IJavaScriptExecutor)webDriver).ExecuteScript("arguments[0].click()", alert);
            status = true;
        }

        return status;

How do I handle such a dialog box(refer to the attached angularjs-image.png) and ensure that the same is accepted when it appears.

Thanks.

angularjs-image.PNG

Xiang Dong

unread,
Jul 10, 2017, 11:17:06 PM7/10/17
to seleniu...@googlegroups.com


Does you want to click the dialog or button on the dialog, your xpath below looks like the dialog itself, click it wont accept or cancel the dialog. you can use the text "yes", "No", "cancel" with xpath to look up the button directly and click it.

Hope it can help you.

--david


From: seleniu...@googlegroups.com <seleniu...@googlegroups.com> on behalf of Vivek Rao <vivekr...@gmail.com>
Sent: Monday, July 10, 2017 12:49 PM
To: Selenium Users
Subject: [selenium-users] Handling Angular JS prompt/dialog box in webpage
 
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a0ca4544-0d5b-4cb7-8a74-eede48c39575%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages