How to handle alert having javascript embedded into a button? : <p>I am automating a sharepoint website using webdriver and java, which contains javascript embedded into the button code. </p>

<p>Please find the HTML snippet of the same :</p>

<pre><code>&lt;input id="ctl00_ContentPlaceHolder1_btnDelete" class="btn" type="submit" onclick="javascript:return confirm('Please select OK to proceed else Cancel.');" value="Delete" name="ctl00$ContentPlaceHolder1$btnDelete"/&gt;
</code></pre>

<p>Please find my code to handle the same :</p>

<pre><code>String js = "if (window.alert.myAlertText == undefined) {window.alert.myAlertText = null;  window.alert = function(msg){ window.alert.myAlertText = msg; };}";
//Click delete button 
((JavascriptExecutor) driver).executeScript("arguments[0].click();", driver.findElement(By.xpath(".//*@id='ctl00_ContentPlaceHolder1_btnDelete']")));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", driver.switchTo().alert(), js);
</code></pre>

<p>But i am not able to accept or dismiss alert.</p>

<p>Kindly help!!!!</p>

<p>Snapshot of the button :</p>

<p><a href="http://i.stack.imgur.com/6UL88.jpg" rel="nofollow">Snapshot Alert</a></p>
