I have a website that generates a page via javascript using window.showmodaldialog. When using the Selenium IDE and firefox I was forced to monkeypatch the javascript to insert a new function to return the value from the dialog, convert window.showmodaldialog to window.open,
driver.execute_script("function setRetVal(mval) { window.myreturnval = mval; }")
driver.execute_script("window.showModalDialog = function( sURL,vArguments, sFeatures) { if(window.myreturnval!=null) { var winarg = window.myreturnval; window.myreturnval = null; return winarg; } modalWin = window.open(sURL, vArguments, sFeatures); return false; }")
and modify onbeforeupload to send the result back.
driver.execute_script("window.onbeforeunload = function() { window.opener.setRetVal(window.returnValue); } ")
I'm now trying to convert to a python + selenium webdriver for testing purposes. I'd really like to get away from injecting new javascript during testing. The problem is that
driver.find_element_by_id("MainContent_buttonAccountLookup").click()
triggers this code
<a href="#" id="MainContent_buttonAccountLookup"
onclick="javascript:callLookup('
Account','<
%=textBoxAccountName.ClientID %>','<%=hiddenFieldAccountId.ClientID %>')
;return false;">
<img alt="Account Lookup" src="../Images/search.GIF" border="0" />
</a>
which doesn't release control back to the python script until the window is closed.
How do I initiate a click so that I can get control of the new window, do my steps and close it?