Returns a list of elements by matching text. Optionally, provide a tag_name to narrow down the search to only elements with the given tag. (Eg: a, button, div, script, span)
(self, text, tag_name=None)
| 362 | return updated_elements |
| 363 | |
| 364 | def find_elements_by_text(self, text, tag_name=None): |
| 365 | """Returns a list of elements by matching text. |
| 366 | Optionally, provide a tag_name to narrow down the search to only |
| 367 | elements with the given tag. (Eg: a, button, div, script, span)""" |
| 368 | self.__add_light_pause() |
| 369 | elements = self.loop.run_until_complete( |
| 370 | self.page.find_elements_by_text(text=text) |
| 371 | ) |
| 372 | updated_elements = [] |
| 373 | if tag_name: |
| 374 | tag_name = tag_name.lower().strip() |
| 375 | for element in elements: |
| 376 | if element and not tag_name: |
| 377 | element = self.__add_sync_methods(element) |
| 378 | if element not in updated_elements: |
| 379 | updated_elements.append(element) |
| 380 | elif ( |
| 381 | element |
| 382 | and tag_name in element.tag_name.lower() |
| 383 | and text.strip() in element.text |
| 384 | ): |
| 385 | element = self.__add_sync_methods(element) |
| 386 | if element not in updated_elements: |
| 387 | updated_elements.append(element) |
| 388 | elif ( |
| 389 | element |
| 390 | and element.parent |
| 391 | and tag_name in element.parent.tag_name.lower() |
| 392 | and text.strip() in element.parent.text |
| 393 | ): |
| 394 | element = self.__add_sync_methods(element.parent) |
| 395 | if element not in updated_elements: |
| 396 | updated_elements.append(element) |
| 397 | elif ( |
| 398 | element |
| 399 | and element.parent |
| 400 | and element.parent.parent |
| 401 | and tag_name in element.parent.parent.tag_name.lower() |
| 402 | and text.strip() in element.parent.parent.text |
| 403 | ): |
| 404 | element = self.__add_sync_methods(element.parent.parent) |
| 405 | if element not in updated_elements: |
| 406 | updated_elements.append(element) |
| 407 | return updated_elements |
| 408 | |
| 409 | def select(self, selector, timeout=None): |
| 410 | """Similar to find_element().""" |
no test coverage detected