@@ -60,6 +60,14 @@ function findContainerWithExecute(container: ElementBase): WebdriverIO.Browser {
6060 return curContainer ;
6161}
6262
63+ const findBrowser = ( container : ElementBase ) : WebdriverIO . Browser => {
64+ let browser : ElementBase | WebdriverIO . Browser = container ;
65+ while ( ( browser as ElementBase ) . parent && browser . capabilities === undefined ) {
66+ browser = ( browser as ElementBase ) . parent ;
67+ }
68+ return browser as WebdriverIO . Browser ;
69+ } ;
70+
6371async function injectDOMTestingLibrary ( container : ElementBase ) {
6472 const browser = findContainerWithExecute ( container ) ;
6573 const shouldInjectDTL = await browser . execute ( function ( ) {
@@ -126,6 +134,12 @@ async function executeQuery(query: QueryName, container: HTMLElement, ...args: S
126134 }
127135
128136 function deserializeArg ( arg : SerializedArg ) : QueryArg {
137+ if ( typeof arg === "object" && arg === null ) {
138+ return undefined ;
139+ }
140+ if ( typeof arg === "object" && ( arg as { nodeType ?: string } ) . nodeType !== undefined ) {
141+ return arg as QueryArg ;
142+ }
129143 if ( typeof arg === "object" && arg . serialized === "RegExp" ) {
130144 return eval ( arg . RegExp ) ;
131145 }
@@ -187,7 +201,8 @@ function createQuery(container: ElementBase & SelectorsBase, queryName: QueryNam
187201 return async ( ...args : QueryArg [ ] ) => {
188202 await injectDOMTestingLibrary ( container ) ;
189203
190- const result : SerializedQueryResult = await findContainerWithExecute ( container ) . execute (
204+ const browser = findBrowser ( container ) ;
205+ const result : SerializedQueryResult = await browser . execute (
191206 executeQuery ,
192207 queryName ,
193208 container as unknown as HTMLElement ,
0 commit comments