Jump to content

WinExists closes the target window


JamesH
 Share

Recommended Posts

I'm using AutoItX to handle a java applet that pops up during some web automation that I'm doing. It works fine on my development system, but if anybody else tries to run it it fails. I tracked down the problem to a WinExists call. When the WinExists is called, the java applet closes and the next Send causes an AccessViolationException. I'm working around it by running an external AutoIt script, but that has problems of its own.

With this going through .NET and COM, and interacting with Java, there's a lot of possible points of failure here. Before I drive myself mad trying to track this down, I just wanted to see if anybody would have insight into what is going wrong. Remember this works on my development system, but nowhere else. Also the external program that does the exact same thing works (mostly) fine.

C#:

AutoItX3Class automator = new AutoItX3Class();
Stopwatch timer = new Stopwatch();

bool done = false;
bool timeout = false;
System.Threading.Thread.Sleep(10000); //Applet sometimes doesn't appear without a wait, possibly related to WinExists problem?
timer.Start();
while (!done && !timeout) //Usually only executed once because the window appears by the time the earlier Sleep is done
{
    if (automator.WinExists("Select a directory to save", "") == 1) //<-Window closes here
    {
        automator.WinActivate("Select a directory to save", "");
        automator.Send("+{END}", 0); //<-AccessViolationException occurs here
        automator.Send(Util.duFilePath + "{ENTER}", 0); //Util.duFilePath is just a string constant with a directory name
        System.Threading.Thread.Sleep(1000);
        automator.ControlClick("Select a directory to save", "", "SunAwtCanvas9", "left", 1, 10, 10); //Click the save button
        done = true;
    }
    else if (automator.WinExists("Warning - Security", "") == 1)
    {
        automator.WinActivate("Warning - Security", "");
        automator.Send("{ENTER}", 0);
    }
    if (!done) timeout = (timer.ElapsedMilliseconds > 120000);
}
timer.Stop();
if (timeout) throw new Exception("Timed out while using export download utility.");
automator.WinWaitClose("Download Progress", "", 120);
Edited by JamesH
Link to comment
Share on other sites

Once I accidentally found some automation/accessibility classes that seemed to have some window checking abilities. The namespace was huge so I returned to the good old AutoItX.

It was a quick look into .net docs. I might be wrong.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...