Thursday, 22 January 2009

Get rid of those pesky IE dialogs with AutoIt

Over the years I have used and reused a variant of a single AutoIt script. The script basically polls windows for a dialog that matches a certain pattern and then performs some action.
I most recently used this to get rid of the IE dialog that pops up using Selenium with IEHTA asking if you want the web page to close the window.

So this script provides an easier way of getting rid of the dialog than sitting there clicking it (or shooting it) - after all, you automate so you don't have to sit there.
The scripts as written get rid of:
  • the IE 6 dialog "The Web page you are viewing is trying to close the window."
  • the IE7 dialog "The webpage you are viewing is trying to close the window."
  • and a FireFox 2 dialog for slow scripts
I mentioned this script in a previous post - but I forgot to upload it. Hence this post.
I have included the compiled .exe version as well but feel free to download AutoIt and compile it for yourself - then you can learn a little more about AutoIt and the scripts.
Variations of this script I have used in the past include:
  • polling for IE proxy password boxes and filling in my details
  • polling for server logins on running machines to allow remote tests to run
  • getting rid of various dialogs that appear when I login to my machine
[download] - get AutoIt too

Should you not want to download it then I have pasted the raw script below:
Global $foundOne
Global $sleepVal
$sleepVal = 1000

While 1

process_window_if_it_exists("Windows Internet Explorer", "The webpage you are viewing is trying to close the window.","Button1")   ;IE7
process_window_if_it_exists("Microsoft Internet Explorer", "The Web page you are viewing is trying to close the window.","Button1") ;IE6
process_window_if_it_exists("Warning: Unresponsive script", "A script on this page may be busy, or it may have stopped responding.", "Continue") ;FireFox 2

if $foundOne < 10 Then
  $sleepVal = 100
  $foundOne = $foundOne + 1
  $foundOne = 11
  $sleepVal = 5000 ;5 seconds


func process_window_if_it_exists($winTitle, $checkMsg, $buttonName)
if WinExists($winTitle,"") Then
  if StringLeft(ControlGetText($winTitle,"","Static2"),StringLen($checkMsg)) = $checkMsg  then
  $foundOne = 1


  1. Just one thing: how do you call your autoit.exe or script from your selenium testcase? Thanks.

    Hi Conor, the script just runs in the background polling for the window so you don't call it from Selenium you run it separately. Hope that helps.

  2. Thanks so much - I was trying to invoke my autoit .exe from my selenium testcase. All working great. Thank you.

  3. Hi,

    I am using Selenium RC with Perl as the scripting language. I want to automate an application using Selenium. But as soon as I login to the site, I get the http basic authentication window which asks me to enter the Username and Password.

    Can you please help me out how can I solve the problem using Autoit? If there's a script along with the detail steps about how to run it, would be great. I have never used Autoit before.

    Hoping for your kind reply. Thanks!

    Rather than using AutoIt you might want to use this solution from the Selenium FAQ.

    If you still want to use AutoIt then the source code in the archive here should helps as it detects a specific window.

    Or you could have a look at some earlier articles I wrote about Autoit