I am automating a web page. Everything goes fine until I press a 'Delete' button that pops up a confirmation Message Box in JavaScript:
Code: Select all
function confirmDelete() {
res = window.confirm("Are you sure you want to delete this record?")
if (res) {
return true;
} else {
return false;
}
}
I've managed to solve it by using another thread that closes teh message box by confirming the deletion :
Code: Select all
Form confirmationForm = Host.Local.FindSingle("/form[@title='Message from webpage']", new Duration(10000));
Button okButton = confirmationForm.FindSingle("button[@text='OK']", new Duration(10000));
Keyboard.Press(System.Windows.Forms.Keys.Enter, new Duration(100));
1. Is there any reason why the thread that is performing the automation tasks gets blocked? (The thread is a STA thread, not the UI thread). Can I do anything so the thread does not get blocked on the message box, so I can continue the automation and close the MessageBox?
2. From this secondary thread I use to workaround the issue, when I obtain the 'OK' button, I cannot execute the Press method on it, because it raises a Ranorex.ActionFailedException, with message {"Action 'press' failed on element '{Button:OK}'."}. The inner exception gives this additional information {"The operation is not supported."}. I've managed to solve this by using a Keyboard.Press. However, I'd prefer to avoid using Keyboard or mouse. Why this code is not working when executing the Press method?
Code: Select all
Form confirmationForm = Host.Local.FindSingle("/form[@title='Message from webpage']", new Duration(10000));
Button okButton = confirmationForm.FindSingle("button[@text='OK']", new Duration(10000));
okButton.Press();