Cannot hook to javascript alert messagehttp://forums.asp.net/t/1537496.aspx/1?Cannot+hook+to+javascript+alert+messageSun, 04 Apr 2010 15:00:56 -040015374963737705http://forums.asp.net/p/1537496/3737705.aspx/1?Cannot+hook+to+javascript+alert+messageCannot hook to javascript alert message <p>How do get the handle of the javascript alert window?</p> <p>I tried with the following code in LTAF but I'm not successful here. I'm not sure how to access the alert window and see whether it is showing the message that I want to show. <br> </p> <p>HtmlPage popup = currentPage.GetPopupPage(1,20);</p> <p><br> </p> <p>Thanks</p> <p>Murali</p> <p><br> </p> <p><br> </p> <p><br> </p> 2010-03-18T09:53:00-04:003737774http://forums.asp.net/p/1537496/3737774.aspx/1?Re+Cannot+hook+to+javascript+alert+messageRe: Cannot hook to javascript alert message <p>Hi check this</p> <p><a href="http://www.willmaster.com/library/features/alert-box-alternative.php">http://www.willmaster.com/library/features/alert-box-alternative.php</a></p> <p><a href="http://www.anyexample.com/webdev/javascript/ie7_javascript_prompt()_alternative.xml">http://www.anyexample.com/webdev/javascript/ie7_javascript_prompt()_alternative.xml</a></p> <p><a href="http://www.webdeveloper.com/forum/showthread.php?t=174223">http://www.webdeveloper.com/forum/showthread.php?t=174223</a></p> <p>&nbsp;</p> 2010-03-18T10:30:23-04:003737822http://forums.asp.net/p/1537496/3737822.aspx/1?Re+Cannot+hook+to+javascript+alert+messageRe: Cannot hook to javascript alert message <p>Hi,</p> <p>Here is an example:</p> <p>JsAlert.aspx:</p> <pre class="prettyprint">&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;JsAlert.aspx.cs&quot; Inherits=&quot;JsAlert&quot; %&gt; &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head runat=&quot;server&quot;&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;div&gt; &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Button&quot; onclick=&quot;Button1_Click&quot; /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <P><BR>JsAlert.aspx.cs:</P><pre class="prettyprint">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class JsAlert : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { ShowMessage(Page, "Hi"); } public static void ShowMessage(Page aPage, string aMessage) { aPage.RegisterStartupScript("AlertMsg", "&lt;script language='javascript'&gt; alert('" + aMessage + "'); &lt;/script&gt;"); } } </pre> <p><br> wish it helps</p> <p>&nbsp;</p> 2010-03-18T10:58:56-04:003742132http://forums.asp.net/p/1537496/3742132.aspx/1?Re+Cannot+hook+to+javascript+alert+messageRe: Cannot hook to javascript alert message <p>Hello Murali, handling of alerts currently is only supported in response to a Click action. You can see an example on the sample website that comes with the code plex download. I copy the test below that shows the API. <br> </p> <p>[WebTestMethod]<br> &nbsp;&nbsp;&nbsp; public void HandleConfirmPopUp()<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HtmlPage page = new HtmlPage(&quot;ScriptSamples.aspx&quot;);<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // click on the button and cancel the confirm<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page.Elements.Find(&quot;ButtonWithConfirm&quot;).Click(new CommandParameters(WaitFor.None,PopupAction.ConfirmCancel));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Assert.AreEqual(&quot;&quot;, page.Elements.Find(&quot;Label1&quot;).GetInnerText());<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // click on the button and accept the confirm<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page.Elements.Find(&quot;ButtonWithConfirm&quot;).Click(new CommandParameters(WaitFor.Postback, PopupAction.ConfirmOK));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Assert.AreEqual(&quot;The Button was clicked.&quot;, page.Elements.Find(&quot;Label1&quot;).GetInnerText());<br> &nbsp;&nbsp;&nbsp; }</p> <p>- Federico<br> </p> <p><br> </p> 2010-03-21T01:33:07-04:003743320http://forums.asp.net/p/1537496/3743320.aspx/1?Re+Cannot+hook+to+javascript+alert+messageRe: Cannot hook to javascript alert message <p>Thanks Federico. I had a look at the sample site. It looks like the Assert is based on what the server returns. </p> <p>In my case, the validation happens at the client. For e.g. I need to check whether mandatory fields have been provided and I provide an alert message (which differs based on what fields have been populated). Is it not possible for me to grab that alert and Assert on the message?</p> <p><br> </p> <p>Thanks</p> <p>Murali<br> </p> 2010-03-22T05:40:55-04:003766774http://forums.asp.net/p/1537496/3766774.aspx/1?Re+Cannot+hook+to+javascript+alert+messageRe: Cannot hook to javascript alert message <p>I see what you are saying, this is a little know feature, but when you issue a Click command using the CommandParameters overload, the text of the alert will be captured and available through the PopupText property. Here is a sample:</p> <p></p> &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp;// click on the button, cancel the confirm and verify alert text&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CommandParameters commandParams = new CommandParameters(WaitFor.None, PopupAction.ConfirmCancel);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;page.Elements.Find(&quot;ButtonWithConfirm&quot;).Click(commandParams);&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Assert.AreEqual(&quot;string from the alert&quot;, commandParams.PopupText);&lt;/div&gt; <p></p> <p>// click on the button, cancel the confirm and verify alert text</p> <p>CommandParameters commandParams = new CommandParameters(WaitFor.None, PopupAction.ConfirmCancel);</p> <p>page.Elements.Find(&quot;ButtonWithConfirm&quot;).Click(commandParams);</p> <p>Assert.AreEqual(&quot;string from the alert&quot;, commandParams.PopupText);</p> <p></p> <p>Hope this helps,</p> <p>Federico</p> <p></p> 2010-04-04T15:00:56-04:00