3

I am automating a form page using Selenium RC (C#). After I click 'Submit' button, I get an alert 'Records Edited Successfully!'. The title of this alert box is 'The page at http://www.******.com says:'.

But Selenium doesn't see this alert. And I can't work around it.

Here is what I've tried:

selenium.Click("ctl00_Content_ctl00_btnSubmit");
selenium.WaitForPageToLoad("30000");

Result: I get the following error: "Selenium.SeleniumException : Timed out after 30000ms"

Then I tried:

selenium.Click("ctl00_Content_ctl00_btnSubmit");
selenium.OpenWindow("", "The page at The page at http://www.******.com says:");
selenium.Close();
selenium.WaitForPageToLoad("30000");

Result: Three windows are opened (site, alert and extra window). Nothing gets closed. I get the following error: "Selenium.SeleniumException : Timed out after 30000ms"

Then I tried:

selenium.Click("ctl00_Content_ctl00_btnSubmit");
selenium.SelectWindow("The page at The page at http://www.******.com says:");
selenium.Close();
selenium.WaitForPageToLoad("30000");

Result: I get the following error: "Could not find window with title 'The page at http://www.******.com says:'"

Any suggestions? Please help to overcome this obstacle.

Prostak
  • 3,565
  • 7
  • 35
  • 46

2 Answers2

4

Apparently the easiest way to do this is to use script to redefine the alert() function to something that doesn't popup a dialog.

((JavascriptExecutor) fDriver).executeScript(
  "window.alert = function(msg) { return true; }"
); 
scunliffe
  • 62,582
  • 25
  • 126
  • 161
  • Too extreme solution in my case. I don't want (and don't have authority) to change the code of the website. – Prostak Nov 18 '10 at 20:54
  • 1
    I'm not in any way suggesting that you *change* the website... I'm suggesting that in your Selenium script, you "inject" a tidbit of JavaScript when you are running *automated tests* only, to override the alert() function to just return true. ( you can do the same with confirm, etc.) - Since there is no need/desire for user interaction you aren't causing any problems, and certainly not changing the *actual* code base. – scunliffe Nov 18 '10 at 20:58
  • hmm interesting....How do I 'inject a tidbit'? Do I enter it inside my C# [Test] method? Could you give a step by step instructions? Thanks. – Prostak Nov 19 '10 at 17:32
1

Finally I've found a workaround:

    selenium.Click("ctl00_Content_ctl00_btnSubmit");                        
    Thread.Sleep(5000);
    selenium.KeyDownNative("32");
    selenium.KeyUpNative("32");

Wish you all the best, everyone!

Prostak
  • 3,565
  • 7
  • 35
  • 46