Skip to content

Commit

Permalink
Create return_active_element method in Base class.
Browse files Browse the repository at this point in the history
Added return_active_element in zindex_sort method
  • Loading branch information
renanllisboa committed Dec 27, 2023
1 parent e8fe8e0 commit eb4809b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tir/technologies/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ def web_scrap(self, term, scrap_type=enum.ScrapType.TEXT, optional_term=None, la
except Exception as e:
self.log_error(str(e))

def zindex_sort (self, elements, reverse=False):
def zindex_sort (self, elements, reverse=False, active_tab=True):
"""
[Internal]
Expand All @@ -1018,7 +1018,10 @@ def zindex_sort (self, elements, reverse=False):
>>> #Calling the method
>>> self.zindex_sort(elements, True)
"""
if isinstance(elements, list):
if active_tab:
elements = self.return_active_element(elements)
else:
isinstance(elements, list)
elements.sort(key=lambda x: self.search_zindex(x), reverse=reverse)

return elements
Expand Down Expand Up @@ -1387,3 +1390,19 @@ def find_by_locator(self, locator, selector, shadow_root):
self.log_error(f"Element {element} doesn't found")

return element

def return_active_element(self, elements):

if isinstance(elements, list):
filtered_element = list(
filter(lambda x: hasattr(x.find_parent('wa-tab-page'), 'attrs') if x else None, elements))

if filtered_element:
non_blocked_element = list(filter(lambda x: 'blocked' not in x.attrs, filtered_element))
active_element = list(filter(lambda x: 'active' in x.find_parent('wa-tab-page').attrs, non_blocked_element))
if active_element:
return active_element
else:
return elements
else:
return elements

0 comments on commit eb4809b

Please sign in to comment.