MouseClick malfunctions

General discussion about the Phantom Automation Language and related tools.

MouseClick malfunctions

Postby Orion on Thu Dec 09, 2010 3:35 am

Okay, this is really wierd.

I've got an application in development. I was literally minutes away from completing it. It's been running fine for an hour or so and I was just tweaking it here and there.

Then, <Window>.MouseClick(ibutton, ix, iy, itype); stopped working.

The application Phantom is running against is a Java app running as a pop-up in an IE window. For hours and hours Click works just fine in the declared window. Then, it started clicking in a different window. The window OJIN pops up the window MAIN after you go through the window LOGIN. Life is good. Main...SetText and Main...TypeKeys work just fine but Main...MouseClick(...); executes its clicks in the OJIN window.


Here's a grossly simplified test-code I wrote to verify that's what was happening - Any ideas at ALL?
use "OJIN.dec";

use "Login.dec";

use "Main.dec";

string sURL = "****";

bool OK;

#sUser and sPW are passed parameters upon calling (Username and Password) Phantom.

System("C:\\Program Files\\Internet Explorer\\iexplore.exe " + sURL);

#NOTE: I had a window Main = MainWin... declaration here but that stopped working after a half dozen runs and
# Phantom decided that the variable already existed at this point
OK = WaitForWindow(OJIN, 20);

if(OK) {

OJIN.TypeKeys("<TAB>" + sURL + "<ENTER>");

window Login = MainWin("*OJIN*", "SunAwtFrame");

OK = WaitForWindow(Login, 20);

if(OK) {

Login.MainWin(1, "SunAwtCanvas").MainWin(1, "Edit").SetText(sUser);

Login.MainWin(1, "SunAwtCanvas").MainWin(2, "Edit").SetText(sPW);

if(!Exists(Login.MainWin(1, "SunAwtCanvas").MainWin(1, "Button"))){



Login.MainWin(1, "SunAwtCanvas").MainWin(2, "Edit").TypeKeys("<TAB><ENTER>");

window Main = MainWin("OJIN OnLine (", "SunAwtFrame");

OK = WaitForWindow(Main, 20);




if(OK) {

#Here it clicks in window OJIN rather than MAIN - I've tried a dozen different variations on forcing it to
#click in MAIN but all clicks go to OJIN.

Main.MainWin(1, "Edit").MouseClick(0, 720, 112, 1);

Main.MainWin(1, "Edit").MouseMove(40, 112);

Main.MainWin(1, "Edit").MouseClick(2, 40, 112, 0);

Posts: 4
Joined: Sat Dec 04, 2010 12:41 am

Re: MouseClick malfunctions

Postby Orion on Thu Dec 09, 2010 8:15 pm

Just a note to new users -
The window.MouseClick(i, i, i, i); method is unreliable, apparently (unless I've done something really wrong with my calling and I've tried about a dozen different ways to call this method). A work around is to maximize the window you want to use and use the screen-relative MouseClick(i, i, i, i) instead.

THAT seems to be working correctly - well for now at least. The method worked most of yesterday too. LOL

Posts: 4
Joined: Sat Dec 04, 2010 12:41 am

Re: MouseClick malfunctions

Postby SpiritualMadMan on Mon Dec 13, 2010 12:50 pm

Same thing happened to me!

Literally minutes away from cleaning up and firming the script and suddenly the scripts are selecting the wrong buttons!

Even after reverifying the co-ordinates as correct!
Posts: 20
Joined: Mon Dec 06, 2010 4:02 pm

Re: MouseClick malfunctions

Postby john on Mon Dec 13, 2010 7:54 pm

Hi All-

Orion, I think we resolved this issue via a support e-mail. In your case, it was a matter of two windows having identical characteristics (tags and classes identical), so Phantom was using the first one it found. Here was the response to that e-mail for everyone's benefit:

One option you could use to distinguish between the windows, particularly if they have the exact same title (tag) and the exact same class, is to capture and use the unique window handle:

Code: Select all
# Start Main somehow

int mainHandle = MainWin("Common Tag", "Common Class").GetHandle();
window Main;

# Start OJIN somehow

# This will get the OJIN since it is a 'top level' window on the screen (Main is now in the background, presumably)
int ojinHandle = MainWin("Common Tag", "Common Class").GetHandle();
window OJIN;

# Now you can use OJIN and Main

See the 'GetHandle' function in the Phantom help file for more information on this.

You can also set the tag of the first window that opens to something else:

Code: Select all
MainWin("Common Tag", "Common Class").SetText("Main Text");

This would change the title of the window to something unique. Then you would access it as:

Code: Select all
window Main;
Main.Tag = "Main Text";
Main.Class = "Common Class";

# Or you could use MainWin:
MainWin("Main Text", "Common Class").DoSomething();

This applies if both windows have exactly the same text and class. This also only applies to top-level windows. If multiple child windows have the same class and tag, you can use arrays (See 'window arrays' under the 'window' keyword in Phantom's help file).

In both these cases, you would have to do this each time the windows are opened, but you could always place it in a Phantom function.

Editing the declarations file will only help if there is some difference between the actual class names and tags (text) of the window. If two top-level windows have exactly the same class and tag, then Phantom can only use the first one it finds since it can't distinguish between them.

Is there another issue that is popping up? The basic MouseClick function is generally very reliable, so I would like to know if there are other issues with it. As many details as possible are appreciated!

Posts: 27
Joined: Wed Apr 22, 2009 12:32 pm

Return to Phantom

Who is online

Users browsing this forum: No registered users and 1 guest