1

Problem: In IE11, a dialog alert is displayed of "Are you sure you want to leave this page?" with two options, 'Leave this page' or Stay on this page'.

In object spy, this is what is captured:

browser.Describe<IDialog>(new DialogDescription
            {
                IsOwnedWindow = true,
                IsChildWindow = false,
                Text = @"Windows Internet Explorer",
                NativeClass = @"#32770"
            }).Describe<IButton>(new ButtonDescription
            {
                Text = @"&Leave this page",
                NativeClass = @"Button"
            });

How can I click on the 'Leave this option'?

BK Hasan
  • 121
  • 1
  • 1
  • 9

1 Answers1

1

Store that description in a variable, like so:

var theButton = Desktop.Describe<IWindow>(new WindowDescription
            {
                IsOwnedWindow = true,
                IsChildWindow = false,
                WindowTitleRegExp = @"Google Chrome"
            }).Describe<IDialog>(new DialogDescription
            {
                IsOwnedWindow = true,
                IsChildWindow = false,
                Text = @"Windows Internet Explorer",
                NativeClass = @"#32770"
            }).Describe<HP.LFT.SDK.StdWin.IButton>(new HP.LFT.SDK.StdWin.ButtonDescription
            {
                Text = @"&Leave this page",
                NativeClass = @"Button"
            });

and then simply perform click on it, like so:

theButton.Click();

Notes:

  • the parent, in this case, is a Desktop app, not the browser
  • since we use native app using StdWin technology, we need to refer to the proper namespace:
    using HP.LFT.SDK.StdWin;
  • since we are now using two namespaces that both have IButtons, we need to use the fully qualified name, where the case
Adelin
  • 7,809
  • 5
  • 37
  • 65
  • I'm getting the following errors: The type or namespace name 'DialogDescription' could not be found (are you missing a using directive or an assembly reference?) The type or namespace name 'IDialog' could not be found (are you missing a using directive or an assembly reference?) 'ButtonDescription' does not contain a definition for 'NativeClass' Here's my references: using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using HP.LFT.SDK; using System.Diagnostics; using System.Threading; using HP.LFT.SDK.Web; using HP.LFT.Report; using System.Drawing; – BK Hasan Apr 10 '19 at 19:42
  • you also need `using HP.LFT.SDK.StdWin`, that is where ButtonDescription and DialogDescription are coming from – Adelin Apr 10 '19 at 21:21
  • I'm getting this error after adding it: Error CS0104: 'ButtonDescription' is an ambiguous reference between 'HP.LFT.SDK.StdWin.ButtonDescription' and 'HP.LFT.SDK.Web.ButtonDescription' – BK Hasan Apr 15 '19 at 17:46
  • Use the fully qualified name: HP.LFT.SDK.StdWin.ButtonDescription – Adelin Apr 15 '19 at 17:53
  • Added more details in the answer itself – Adelin Apr 15 '19 at 19:58