I am currently working on automating a SharePoint website using WebDriver and Java. The website has JavaScript embedded in the button code.
Here is the HTML snippet for the button:
<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"/>
Below is the code I have written to handle this:
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);
However, I am facing difficulties in accepting or dismissing the alert.
Please provide assistance!
Snapshot of the button :