@@ -311,51 +311,63 @@ def wait_text_on_page(text: str, timeout: int = 30):
311
311
312
312
@decorators ._must_have_supported_selector_type
313
313
@decorators ._must_have_driver_initialized
314
- def find_element (selector_type : str , selector : str ) -> WebElement :
314
+ def find_element (selector_type : str , selector : str , parent_el : WebElement = None ) -> WebElement :
315
315
"""
316
316
Find the first element matching the given selector and selector type.
317
+ If parent_el is set, it will search for a child element.
317
318
"""
318
319
_log .debug (
319
320
f"finding element matching { selector } by selector type { selector_type } " )
320
321
321
322
try :
322
- return _driver .find_element (getattr (By , selector_type ), selector )
323
+ root_el = _driver
324
+ if parent_el is not None :
325
+ root_el = parent_el
326
+
327
+ return root_el .find_element (getattr (By , selector_type ), selector )
323
328
except :
324
329
return None
325
330
326
331
327
332
@decorators ._must_have_supported_selector_type
328
333
@decorators ._must_have_driver_initialized
329
- def find_select_element (selector_type : str , selector : str ) -> Select :
334
+ def find_select_element (selector_type : str , selector : str , parent_el : WebElement = None ) -> Select :
330
335
"""
331
336
Find the first element matching the given selector and selector type and return it as a Select wrapped WebElement.
337
+ If parent_el is set, it will search for a child element.
332
338
"""
333
339
_log .debug (
334
340
f"finding element matching { selector } by selector type { selector_type } and returning it as a Select wrapped WebElement" )
335
341
336
- return Select (find_element (selector_type , selector ))
342
+ return Select (find_element (selector_type , selector , parent_el ))
337
343
338
344
339
345
@decorators ._must_have_supported_selector_type
340
346
@decorators ._must_have_driver_initialized
341
- def find_elements (selector_type : str , selector : str ) -> List [WebElement ]:
347
+ def find_elements (selector_type : str , selector : str , parent_el : WebElement = None ) -> List [WebElement ]:
342
348
"""
343
349
Find all elements matching the given selector and selector type.
350
+ If parent_el is set, it will search for child elements.
344
351
"""
345
352
_log .debug (
346
353
f"finding elements matching { selector } by selector type { selector_type } " )
347
354
348
355
try :
349
- return _driver .find_elements (getattr (By , selector_type ), selector )
356
+ root_el = _driver
357
+ if parent_el is not None :
358
+ root_el = parent_el
359
+
360
+ return root_el .find_elements (getattr (By , selector_type ), selector )
350
361
except :
351
362
return None
352
363
353
364
354
365
@decorators ._must_have_supported_selector_type
355
366
@decorators ._must_have_driver_initialized
356
- def wait_element_exists (selector_type : str , selector : str , timeout : int = 10 ) -> WebElement :
367
+ def wait_element_exists (selector_type : str , selector : str , timeout : int = 10 , parent_el : WebElement = None ) -> WebElement :
357
368
"""
358
369
Waits for an element matching the given selector by selector_type to exist on the current page.
370
+ If parent_el is set, it will wait for a child element.
359
371
"""
360
372
_log .debug (
361
373
f"waiting for element matching { selector } by selector type { selector_type } to exist" )
@@ -367,14 +379,15 @@ def wait_element_exists(selector_type: str, selector: str, timeout: int = 10) ->
367
379
max_time = timeout
368
380
)
369
381
370
- return b (find_element )(selector_type , selector )
382
+ return b (find_element )(selector_type , selector , parent_el )
371
383
372
384
373
385
@decorators ._must_have_supported_selector_type
374
386
@decorators ._must_have_driver_initialized
375
- def wait_element_not_exists (selector_type : str , selector : str , timeout : int = 10 ):
387
+ def wait_element_not_exists (selector_type : str , selector : str , timeout : int = 10 , parent_el : WebElement = None ):
376
388
"""
377
389
Waits for an element matching the given selector by selector_type to not exist on the current page.
390
+ If parent_el is set, it will wait for a child element.
378
391
"""
379
392
_log .debug (
380
393
f"waiting for element matching { selector } by selector type { selector_type } to not exist" )
@@ -386,7 +399,7 @@ def wait_element_not_exists(selector_type: str, selector: str, timeout: int = 10
386
399
max_time = timeout
387
400
)
388
401
389
- b (find_element )(selector_type , selector )
402
+ b (find_element )(selector_type , selector , parent_el )
390
403
391
404
392
405
@decorators ._must_have_driver_initialized
0 commit comments