Skip to content

Commit 99a2395

Browse files
Logs fixed for allow hidden
1 parent c03b390 commit 99a2395

File tree

1 file changed

+117
-49
lines changed

1 file changed

+117
-49
lines changed

Framework/Built_In_Automation/Shared_Resources/LocateElement.py

Lines changed: 117 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,11 @@ def Get_Element(step_data_set, driver, query_debug=False, wait_enable=True, retu
151151
)
152152
return "failed"
153153

154-
# wait_time = int(sr.Get_Shared_Variables("element_wait"))
155-
# etime = time.time() + wait_time # Default time to wait for an element
156-
# while (
157-
# time.time() < etime
158-
# ): # Our own built in "wait" until True because sometimes elements do not appear fast enough
159-
# If driver is pyautogui, perform specific get element function and exit
160154
if driver_type == "pyautogui":
161155
result = _pyautogui(step_data_set)
162156
if save_parameter != "": # save element to a variable
163157
sr.Set_Shared_Variables(save_parameter, result)
164-
return result # Return on pass
165-
# if not wait_enable:
166-
# CommonUtil.ExecLog(
167-
# sModuleInfo,
168-
# "Element not found. Waiting is disabled, so returning",
169-
# 3,
170-
# )
171-
# return result # If asked not to loop, return the failure
172-
# continue # If fail, but instructed to loop, do so
158+
return result
173159

174160
# here we switch driver if we need to
175161
_switch(step_data_set)
@@ -198,7 +184,7 @@ def Get_Element(step_data_set, driver, query_debug=False, wait_enable=True, retu
198184
else:
199185
result = "failed"
200186

201-
# if user sends optional option check if element is displayed or not. We may need to add more
187+
# if user sends optional option check if element is displayed or not. We may need to add more
202188
# items here such as enabled, visible and such.
203189

204190
try:
@@ -641,7 +627,7 @@ def _get_xpath_or_css_element(element_query, css_xpath, index_number=False, Filt
641627
start = time.time()
642628
#end = start + int(sr.Get_Shared_Variables("element_wait"))
643629
end = 10
644-
x=0
630+
x = 0
645631
#while time.time() < end:
646632
while x <end:
647633
x = x+1
@@ -724,60 +710,142 @@ def _get_xpath_or_css_element(element_query, css_xpath, index_number=False, Filt
724710
By.CSS_SELECTOR, element_query
725711
)
726712

727-
if all_matching_elements_visible_invisible != False:
713+
if all_matching_elements_visible_invisible:
728714
break
729-
730-
time.sleep(0.5)
715+
time.sleep(0.5)
731716
# end of while loop
732717

733-
734-
if exception_cnd == True:
735-
return "failed"
718+
if exception_cnd:
719+
return False
736720

737721
all_matching_elements = filter_elements(all_matching_elements_visible_invisible, Filter)
722+
if Filter == "allow hidden":
723+
displayed_len = len(filter_elements(all_matching_elements_visible_invisible, ""))
724+
hidden_len = len(all_matching_elements_visible_invisible) - displayed_len
725+
else:
726+
displayed_len = len(all_matching_elements)
727+
hidden_len = len(all_matching_elements_visible_invisible) - displayed_len
738728

739729
if return_all_elements:
740-
CommonUtil.ExecLog(
741-
sModuleInfo,
742-
"Found %s elements with given condition. Returning all of them" % len(all_matching_elements),
743-
1,
744-
)
730+
if Filter == "allow hidden":
731+
CommonUtil.ExecLog(
732+
"",
733+
"Found %s hidden elements and %s displayed elements. Returning all of them"
734+
% (hidden_len, displayed_len),
735+
1
736+
)
737+
else:
738+
CommonUtil.ExecLog(
739+
"",
740+
"Found %s hidden elements and %s displayed elements. Returning %s displayed elements only"
741+
% (hidden_len, displayed_len, displayed_len),
742+
1
743+
)
745744
return all_matching_elements
746745
elif len(all_matching_elements) == 0:
746+
if hidden_len > 0 and Filter != "allow hidden":
747+
CommonUtil.ExecLog(
748+
"",
749+
"Found %s hidden elements and no displayed elements. Nothing to return.\n" % hidden_len +
750+
"To get hidden elements add a row (\"allow hidden\", \"optional option\", \"yes\")",
751+
3
752+
)
747753
return False
748754
elif len(all_matching_elements) == 1 and index_number == False:
755+
if hidden_len > 0 and Filter != "allow hidden":
756+
CommonUtil.ExecLog(
757+
"",
758+
"Found %s hidden elements and %s displayed elements. Returning the displayed element only\n" % (hidden_len, displayed_len) +
759+
"To get hidden elements add a row (\"allow hidden\", \"optional option\", \"yes\") and also consider providing index",
760+
2
761+
)
762+
elif Filter == "allow hidden":
763+
CommonUtil.ExecLog("", "Found %s hidden element and %s displayed element" % (hidden_len, displayed_len), 1)
749764
return all_matching_elements[0]
750765
elif len(all_matching_elements) > 1 and index_number == False:
751-
CommonUtil.ExecLog(
752-
sModuleInfo,
753-
"Warning: found %s elements with given condition. Returning first item. Consider providing index"
754-
% len(all_matching_elements),
755-
2,
756-
)
766+
if hidden_len > 0 and Filter != "allow hidden":
767+
CommonUtil.ExecLog(
768+
"",
769+
"Found %s hidden elements and %s displayed elements. Returning the first displayed element only\n" % (hidden_len, displayed_len) +
770+
"To get hidden elements add a row (\"allow hidden\", \"optional option\", \"yes\") and also consider providing index",
771+
2
772+
)
773+
elif Filter != "allow hidden":
774+
CommonUtil.ExecLog(
775+
"",
776+
"Found %s displayed elements. Returning the first displayed element only. Consider providing index" % displayed_len,
777+
2
778+
)
779+
else:
780+
CommonUtil.ExecLog(
781+
"",
782+
"Found %s hidden elements and %s displayed elements. Returning the first element only. Consider providing index" % (hidden_len, displayed_len),
783+
2
784+
)
757785
return all_matching_elements[0]
758786
elif len(all_matching_elements) == 1 and abs(index_number) > 0:
759-
CommonUtil.ExecLog(
760-
sModuleInfo,
761-
"Warning: we only found single element but you provided an index number greater than 0. Returning the only element",
762-
2,
763-
)
764-
return all_matching_elements[0]
765-
elif len(all_matching_elements) > 1 and index_number != False:
766-
if (len(all_matching_elements) - 1) < abs(index_number):
787+
if hidden_len > 0 and Filter != "allow hidden":
767788
CommonUtil.ExecLog(
768789
sModuleInfo,
769-
"Error: your index: %s exceed the the number of elements found: %s"
770-
% (index_number, len(all_matching_elements) - 1),
771-
3,
790+
"Found %s hidden elements and %s displayed elements but you provided an index number greater than 0. Returning the only displayed element\n" % (hidden_len, displayed_len) +
791+
"To get hidden elements add a row (\"allow hidden\", \"optional option\", \"yes\") and also consider providing correct index",
792+
2,
772793
)
773-
return "failed"
774-
else:
794+
elif Filter != "allow hidden":
775795
CommonUtil.ExecLog(
776796
sModuleInfo,
777-
"Total elements found are: %s but returning element number: %s"
778-
% (len(all_matching_elements), index_number),
797+
"Found 0 hidden elements and %s displayed elements but you provided an index number greater than 0. Returning the only displayed element\n" % displayed_len,
779798
2,
780799
)
800+
elif Filter == "allow hidden":
801+
CommonUtil.ExecLog(
802+
"",
803+
"Found %s hidden element and %s displayed element but you provided an index number greater than 0. Returning the only element" % (hidden_len, displayed_len),
804+
2
805+
)
806+
return all_matching_elements[0]
807+
elif len(all_matching_elements) > 1 and index_number != False:
808+
if (len(all_matching_elements) - 1) < abs(index_number):
809+
if hidden_len > 0 and Filter != "allow hidden":
810+
CommonUtil.ExecLog(
811+
"",
812+
"Found %s hidden elements and %s displayed elements. Index exceeds the number of displayed elements found\n" % (hidden_len, displayed_len) +
813+
"To get hidden elements add a row (\"allow hidden\", \"optional option\", \"yes\") and also consider providing correct index",
814+
3
815+
)
816+
elif Filter != "allow hidden":
817+
CommonUtil.ExecLog(
818+
"",
819+
"Found 0 hidden elements and %s displayed elements. Index exceeds the number of displayed elements found" % displayed_len,
820+
3
821+
)
822+
else:
823+
CommonUtil.ExecLog(
824+
"",
825+
"Found %s hidden elements and %s displayed elements. Index exceeds the number of elements found" % (hidden_len, displayed_len),
826+
3
827+
)
828+
return "failed"
829+
else:
830+
if hidden_len > 0 and Filter != "allow hidden":
831+
CommonUtil.ExecLog(
832+
"",
833+
"Found %s hidden elements and %s displayed elements. Returning the displayed element of index %s\n" % (hidden_len, displayed_len, index_number) +
834+
"To get hidden elements add a row (\"allow hidden\", \"optional option\", \"yes\")",
835+
1
836+
)
837+
elif Filter != "allow hidden":
838+
CommonUtil.ExecLog(
839+
"",
840+
"Found 0 hidden elements and %s displayed elements. Returning the displayed element of index %s" % (displayed_len, index_number),
841+
1
842+
)
843+
else:
844+
CommonUtil.ExecLog(
845+
"",
846+
"Found %s hidden elements and %s displayed elements. Returning the element of index %s" % (hidden_len, displayed_len, index_number),
847+
1
848+
)
781849
return all_matching_elements[index_number]
782850
else:
783851
return "failed"

0 commit comments

Comments
 (0)