Search code examples
c#seleniumonloadrcjavascript

What would be a walkaround for JavaScript alerts that are generated in a page's onload() using Selenium?


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.


Solution

  • 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!