This is a migrated thread and some comments may be shown as answers.

Dialog handling problems

3 Answers 168 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kovyar
Top achievements
Rank 1
kovyar asked on 21 Sep 2010, 12:46 PM
Hi all,

I'd like to get some information about a dialog window when I close it, so I try to use code like that:
public void Test1()
{
    Settings settings = new Settings(BrowserType.InternetExplorer, @"d:\log\");
    settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
    Manager manager = new Manager(settings);
    manager.Start();
    manager.LaunchNewBrowser();
 
    manager.ActiveBrowser.NavigateTo("http://aspspider.ws/kovyar/confirm.htm");
 
    Element confButton = manager.ActiveBrowser.Find.ById("confirmbutton");
 
    manager.DialogMonitor.AddDialog(new GenericDialog(manager.ActiveBrowser, "Explorer", true, 1));
    manager.DialogMonitor.Dialogs[0].HandlerDelegate = delegate(IDialog dialog)
    {
        Trace.WriteLine(dialog.Window.Caption);
        Trace.WriteLine(dialog.Window.AllChildren[0].Caption);
        Trace.WriteLine(dialog.Window.AllChildren[1].Caption);
        Trace.WriteLine(dialog.Window.AllChildren[2].Caption);
        Trace.WriteLine(dialog.Window.AllChildren[3].Caption);
        Manager.Current.Desktop.Mouse.Click(MouseClickType.LeftClick, dialog.Window.AllChildren[1].Location);
    };
    manager.DialogMonitor.Start();
    (new HtmlControl(confButton)).Click();
 
    Thread.Sleep(5000);
    manager.DialogMonitor.Stop();
    manager.Dispose();
}

The idea of writing this stuff is here: see "Creating custom dialog handlers" section.
Still it doesn't work at all. The button is pressed, the dialog appears and I collect all the required information (see trace after run).
But the "Cancel" button isn't clicked while the code is very the same as given at the Artoftes site.

OS: WinXP, browser: IE7.

Thanks in advance for any ideas,
Yaroslav





3 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 23 Sep 2010, 01:01 AM
Hello kovyar,

The code:

manager.Current.Desktop.Mouse.Click(MouseClickType.LeftClick, dialog.Window.AllChildren[1].Location);

wants to click on the 2nd child window of the dialog window (the index is 0 based, so 1 means the 2nd array item). Are you sure this is the Cancel button? A Spy++ utility is needed to deconstruct the dialog. If it's trying to click on a button you should see the mouse move and something get clicked. Do you see the mouse move somewhere? Where does it move to?

You might be better off searching for the Cancel button (assuming it is a Win32 window) and then clicking on the window it found using code like this:

Window cancelButton = WindowManager.FindWindowRecursively(dialog.Window.Handle, "Cancel", false, 0);
manager.Current.Desktop.Mouse.Click(MouseClickType.LeftClick, cancelButton.Location);

All the best,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
kovyar
Top achievements
Rank 1
answered on 23 Sep 2010, 11:55 AM
Hi, Cody

Actually, before posting the trouble, I've checked:
1) all the captions of the first four child windows (see trace)
2) location of the button I'm trying to click, and it was the same as Cancel button location

Then I've tried your code with the same result as mine (I mean, no result). BTW, the found Window object is the same for your and my code.

Concerning mouse moves: no, it doesn't move at all. The test simply hangs with the dialog on top of the browser window.
I suggest that Webaii is unable to control Manager.Desktop while alert/confirm dialog is open.
By the way, all the attempts to simulate spacebar or enter key press failed as well.

All the best,
Yaroslav
0
Cody
Telerik team
answered on 06 Oct 2010, 05:24 PM
Hello kovyar,

I did some more research on this and find you are right about mouse actions. I'm going to file a bug on this.

As an alternative you could use a KeyPress instead like this:

manager.DialogMonitor.Dialogs[0].HandlerDelegate = delegate(IDialog dialog)
{
    Log.WriteLine(dialog.Window.Caption);
    Log.WriteLine(dialog.Window.AllChildren[0].Caption);
    Log.WriteLine(dialog.Window.AllChildren[1].Caption);
    Log.WriteLine(dialog.Window.AllChildren[2].Caption);
    Log.WriteLine(dialog.Window.AllChildren[3].Caption);
    Manager.Desktop.KeyBoard.KeyPress(Keys.Enter);
    //Manager.Current.Desktop.Mouse.Click(MouseClickType.LeftClick, dialog.Window.AllChildren[1].Location);
};

The Keys.Enter is defined in the System.Windows.Forms assembly.

Sincerely yours,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
kovyar
Top achievements
Rank 1
Answers by
Cody
Telerik team
kovyar
Top achievements
Rank 1
Share this question
or