简体   繁体   中英

selenium not reading javascript alert in c#

i am using selenium ide for testing my .net website. i am testing login for the website by using selenium. i recorded the steps and as i am testing the code in visual studio the test case is failing. my test case is:

selenium.Open("//login.aspx");
            selenium.Type("fldUsername", "abc");
            selenium.Type("fldPassword", "abc");
            selenium.Click("btnLogin");
            bool log1 = selenium.IsPromptPresent();
            Assert.IsNull(log1);
            selenium.WaitForPageToLoad("80000");

here username and password are incorrect and is giving a alert. but using selenium it is not getting that alert. please someone help me out..

You're using the wrong method. selenium.IsPromptPresent() looks for JavaScript window.prompt() calls. For window.alert() , you need to use selenium.IsAlertPresent() .

For extra credit, replace those two lines with:

Assert.True(selenium.IsAlertPresent());
Assert.AreEqual("your expected alert text", selenium.GetAlert());

That way you make sure that you're getting the "wrong userid/password" alert, not the "no password specified" alert or something else.

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