@@ -168,6 +168,11 @@ export async function changeRootElement(this: NovaWindowsDriver, pathOrNativeWin
168168 if ( elementId . trim ( ) !== '' ) {
169169 await this . sendPowerShellCommand ( /* ps1 */ `$rootElement = ${ new FoundAutomationElement ( elementId ) . buildCommand ( ) } ` ) ;
170170 trySetForegroundWindow ( nativeWindowHandle ) ;
171+ const pidResult = await this . sendPowerShellCommand ( `$rootElement.Current.ProcessId` ) ;
172+ const pid = Number ( pidResult . trim ( ) ) ;
173+ if ( ! isNaN ( pid ) && pid > 0 ) {
174+ this . appProcessIds = [ pid ] ;
175+ }
171176 return ;
172177 }
173178
@@ -184,6 +189,10 @@ export async function changeRootElement(this: NovaWindowsDriver, pathOrNativeWin
184189 this . log . debug ( `Process IDs of ApplicationFrameHost processes (${ processIds . length } ): ` + processIds . join ( ', ' ) ) ;
185190 this . appProcessIds = processIds ;
186191 await this . attachToApplicationWindow ( processIds ) ;
192+ const attachedPid = Number ( ( await this . sendPowerShellCommand ( `$rootElement.Current.ProcessId` ) ) . trim ( ) ) ;
193+ if ( ! isNaN ( attachedPid ) && attachedPid > 0 ) {
194+ this . appProcessIds = [ attachedPid ] ;
195+ }
187196 } else {
188197 this . log . debug ( 'Detected app path to be in the classic format.' ) ;
189198 const normalizedPath = normalize ( path ) ;
@@ -196,6 +205,10 @@ export async function changeRootElement(this: NovaWindowsDriver, pathOrNativeWin
196205 this . log . debug ( `Process IDs of '${ processName } ' processes: ` + processIds . join ( ', ' ) ) ;
197206 this . appProcessIds = processIds ;
198207 await this . attachToApplicationWindow ( processIds ) ;
208+ const attachedPid = Number ( ( await this . sendPowerShellCommand ( `$rootElement.Current.ProcessId` ) ) . trim ( ) ) ;
209+ if ( ! isNaN ( attachedPid ) && attachedPid > 0 ) {
210+ this . appProcessIds = [ attachedPid ] ;
211+ }
199212 }
200213}
201214
0 commit comments