33using OpenQA . Selenium . Appium ;
44using OpenQA . Selenium . Appium . Windows ;
55using System . Drawing ;
6- using System . Windows . Automation ;
76
87namespace WinDynamicDesktop . Tests
98{
@@ -30,7 +29,7 @@ public void ShouldUpdateWallpaper()
3029 {
3130 driver . FindElementByXPath ( "//Window[@Name='Select Language']" ) . Click ( ) ;
3231 driver . FindElementByXPath ( "//Button[@Name='OK']" ) . Click ( ) ;
33- Thread . Sleep ( TimeSpan . FromSeconds ( 5 ) ) ;
32+ Thread . Sleep ( TimeSpan . FromSeconds ( 2 ) ) ;
3433
3534 if ( HandleLocationPrompt ( ) ) Thread . Sleep ( TimeSpan . FromSeconds ( 2 ) ) ;
3635 driver . SwitchTo ( ) . Window ( driver . WindowHandles [ 0 ] ) ;
@@ -64,13 +63,12 @@ public void Dispose()
6463
6564 private bool HandleLocationPrompt ( )
6665 {
67- var dialogMatcher = new PropertyCondition ( AutomationElement . NameProperty , "Let Windows and apps access your location?" ) ;
68- var buttonMatcher = new PropertyCondition ( AutomationElement . NameProperty , "Yes" ) ;
69- AutomationElement dialog = AutomationElement . RootElement . FindFirst ( TreeScope . Children , dialogMatcher ) ;
70- if ( dialog ? . FindFirst ( TreeScope . Descendants , buttonMatcher ) is AutomationElement yesButton &&
71- yesButton . GetCurrentPattern ( InvokePattern . Pattern ) is InvokePattern invokePattern )
66+ if ( driver . WindowHandles . Count == 0 )
7267 {
73- invokePattern . Invoke ( ) ;
68+ // Default focus is on No button, so Shift+Tab to focus Yes, then Enter to confirm
69+ System . Windows . Forms . SendKeys . SendWait ( "+{TAB}" ) ;
70+ Thread . Sleep ( 500 ) ;
71+ System . Windows . Forms . SendKeys . SendWait ( "{ENTER}" ) ;
7472 return true ;
7573 }
7674 return false ;
0 commit comments