Testing a page with an input element like this:
<input name="testInput" onblur="javascript:generateAnAlertAndFocus(this);" />
<script type="text/javascript">
function generateAnAlertAndFocus(inputElement) {
if (inputElement.value == "test") {
alert("Bad value");
inputElement.focus();
}
}
</script>
Using the following Selenium test:
<tr>
<td>type</td>
<td>testInput</td>
<td>test</td>
</tr>
<tr>
<td>verifyAlert</td>
<td>Bad value</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>testInput</td>
<td>somethingelse</td>
</tr>
Selenium fails on the last command with a complaint that there was an unverified alert even though it was verified on the previous command. I know the trick of returning focus to the input element is not portable, but the project that I am currently on has been using this trick quite heavily (only targetting IE... sigh...).
I can only guess that the problem might be that the onblur event handler is being called again when the Fit runner focusses on the next command to estimated.
The problem seems to be the call to focusOnElement in the commandStarted() method of selenium-fitrunner.js
At Mike William's suggestion I tried scrollIntoView() and that seems to solve the problem. I added the following code to the start of focusOnElement:
if (element.scrollIntoView) { element.scrollIntoView(); return; }
Also, given that focusOnElement is only called from within commandStarted() and its purpose is to scroll the element into view, perhaps the function should be renamed to scrollIntoView.