@@ -467,16 +467,18 @@ def get_element_rect(self, locator):
467
467
self ._info ("Element '%s' rect: %s " % (locator , element_rect ))
468
468
return element_rect
469
469
470
- def get_text (self , locator ):
470
+ def get_text (self , locator , first_only : bool = True ):
471
471
"""Get element text (for hybrid and mobile browser use `xpath` locator, others might cause problem)
472
472
473
- Example:
473
+ first_only parameter allow to get the text from the 1st match (Default) or a list of text from all match.
474
474
475
- | ${text} | Get Text | //*[contains(@text,'foo')] |
475
+ Example:
476
+ | ${text} | Get Text | //*[contains(@text,'foo')] | |
477
+ | @{text} | Get Text | //*[contains(@text,'foo')] | ${False} |
476
478
477
479
New in AppiumLibrary 1.4.
478
480
"""
479
- text = self ._get_text (locator )
481
+ text = self ._get_text (locator , first_only )
480
482
self ._info ("Element '%s' text is '%s' " % (locator , text ))
481
483
return text
482
484
@@ -667,10 +669,12 @@ def _element_find_by_text(self, text, exact_match=False):
667
669
_xpath = u'//*[contains(@{},"{}")]' .format ('text' , text )
668
670
return self ._element_find (_xpath , True , True )
669
671
670
- def _get_text (self , locator ):
671
- element = self ._element_find (locator , True , True )
672
+ def _get_text (self , locator , first_only : bool = True ):
673
+ element = self ._element_find (locator , first_only , True )
672
674
if element is not None :
673
- return element .text
675
+ if first_only :
676
+ return element .text
677
+ return [el .text for el in element ]
674
678
return None
675
679
676
680
def _is_text_present (self , text ):
0 commit comments