@@ -291,20 +291,19 @@ def click(
291291 pre_action_url = self.driver.current_url
292292 pre_window_count = len(self.driver.window_handles)
293293 try:
294- if self.browser == "ie" and by == By.LINK_TEXT:
295- # An issue with clicking Link Text on IE means using jquery
294+ if (
295+ by == By.LINK_TEXT
296+ and (
297+ self.browser == "ie" or self.browser == "safari"
298+ )
299+ ):
296300 self.__jquery_click(selector, by=by)
297- elif self.browser == "safari":
298- if by == By.LINK_TEXT:
299- self.__jquery_click(selector, by=by)
300- else:
301- self.__js_click(selector, by=by)
302301 else:
303302 href = None
304303 new_tab = False
305304 onclick = None
306305 try:
307- if self.headless and element.tag_name == "a":
306+ if self.headless and element.tag_name.lower() == "a":
308307 # Handle a special case of opening a new tab (headless)
309308 href = element.get_attribute("href").strip()
310309 onclick = element.get_attribute("onclick")
@@ -343,11 +342,8 @@ def click(
343342 self.__scroll_to_element(element, selector, by)
344343 except Exception:
345344 pass
346- if self.browser == "safari":
347- if by == By.LINK_TEXT:
348- self.__jquery_click(selector, by=by)
349- else:
350- self.__js_click(selector, by=by)
345+ if self.browser == "safari" and by == By.LINK_TEXT:
346+ self.__jquery_click(selector, by=by)
351347 else:
352348 element.click()
353349 except ENI_Exception:
@@ -364,7 +360,7 @@ def click(
364360 new_tab = False
365361 onclick = None
366362 try:
367- if element.tag_name == "a":
363+ if element.tag_name.lower() == "a":
368364 # Handle a special case of opening a new tab (non-headless)
369365 href = element.get_attribute("href").strip()
370366 onclick = element.get_attribute("onclick")
@@ -1449,10 +1445,11 @@ def get_text(self, selector, by="css selector", timeout=None):
14491445 try:
14501446 element_text = element.text
14511447 if self.browser == "safari":
1452- element_text = element.get_attribute("innerText")
1453- if element.tag_name == "input":
1454- element_text = element.get_property("value")
1455- if element.tag_name == "textarea":
1448+ if element.tag_name.lower() in ["input", "textarea"]:
1449+ element_text = element.get_attribute("value")
1450+ else:
1451+ element_text = element.get_attribute("innerText")
1452+ elif element.tag_name.lower() in ["input", "textarea"]:
14561453 element_text = element.get_property("value")
14571454 except (StaleElementReferenceException, ENI_Exception):
14581455 self.wait_for_ready_state_complete()
@@ -1462,8 +1459,11 @@ def get_text(self, selector, by="css selector", timeout=None):
14621459 )
14631460 element_text = element.text
14641461 if self.browser == "safari":
1465- element_text = element.get_attribute("innerText")
1466- if element.tag_name == "input":
1462+ if element.tag_name.lower() in ["input", "textarea"]:
1463+ element_text = element.get_attribute("value")
1464+ else:
1465+ element_text = element.get_attribute("innerText")
1466+ elif element.tag_name.lower() in ["input", "textarea"]:
14671467 element_text = element.get_property("value")
14681468 return element_text
14691469
@@ -2219,9 +2219,6 @@ def hover_and_click(
22192219 if self.mobile_emulator:
22202220 # On mobile, click to hover the element
22212221 dropdown_element.click()
2222- elif self.browser == "safari":
2223- # Use the workaround for hover-clicking on Safari
2224- raise Exception("This Exception will be caught.")
22252222 else:
22262223 page_actions.hover_element(self.driver, dropdown_element)
22272224 except Exception:
@@ -2264,6 +2261,12 @@ def hover_and_click(
22642261 )
22652262 ):
22662263 self.__switch_to_newest_window_if_not_blank()
2264+ elif self.browser == "safari":
2265+ # Release the hover by hovering elsewhere
2266+ try:
2267+ page_actions.hover_on_element(self.driver, "body")
2268+ except Exception:
2269+ pass
22672270 if self.demo_mode:
22682271 if self.driver.current_url != pre_action_url:
22692272 self.__demo_mode_pause_if_active()
@@ -2625,10 +2628,11 @@ def get_select_options(
26252628 raise Exception("The attribute must be in %s" % allowed_attributes)
26262629 selector, by = self.__recalculate_selector(selector, by)
26272630 element = self.wait_for_element(selector, by=by, timeout=timeout)
2628- if element.tag_name != "select":
2631+ if element.tag_name.lower() != "select":
26292632 raise Exception(
26302633 'Element tag_name for get_select_options(selector) must be a '
2631- '"select"! Actual tag_name found was: "%s"' % element.tag_name
2634+ '"select"! Actual tag_name found was: "%s"'
2635+ % element.tag_name.lower()
26322636 )
26332637 if by != "css selector":
26342638 selector = self.convert_to_css_selector(selector, by=by)
@@ -2712,9 +2716,13 @@ def load_html_string(self, html_string, new_page=True):
27122716 html_string = html_string.replace("\\ ", " ")
27132717
27142718 if new_page:
2715- self.open("data:text/html,")
2719+ self.open("data:text/html,<head></head><body></body> ")
27162720 inner_head = """document.getElementsByTagName("head")[0].innerHTML"""
27172721 inner_body = """document.getElementsByTagName("body")[0].innerHTML"""
2722+ try:
2723+ self.wait_for_element_present("body", timeout=1)
2724+ except Exception:
2725+ pass
27182726 if not found_body:
27192727 self.execute_script('''%s = \"%s\"''' % (inner_body, html_string))
27202728 elif found_body and not found_head:
@@ -5097,13 +5105,16 @@ def slow_scroll_to(self, selector, by="css selector", timeout=None):
50975105 original_selector, by=original_by, timeout=timeout
50985106 )
50995107 try:
5100- scroll_distance = js_utils.get_scroll_distance_to_element(
5101- self.driver, element
5102- )
5103- if abs(scroll_distance) > constants.Values.SSMD:
5104- self.__jquery_slow_scroll_to(selector, by)
5108+ if self.browser != "safari":
5109+ scroll_distance = js_utils.get_scroll_distance_to_element(
5110+ self.driver, element
5111+ )
5112+ if abs(scroll_distance) > constants.Values.SSMD:
5113+ self.__jquery_slow_scroll_to(selector, by)
5114+ else:
5115+ self.__slow_scroll_to_element(element)
51055116 else:
5106- self.__slow_scroll_to_element(element )
5117+ self.__jquery_slow_scroll_to(selector, by )
51075118 except Exception:
51085119 self.wait_for_ready_state_complete()
51095120 time.sleep(0.12)
@@ -6716,7 +6727,7 @@ def set_text(self, selector, text, by="css selector", timeout=None):
67166727 element = page_actions.wait_for_element_present(
67176728 self.driver, selector, by, timeout
67186729 )
6719- if element.tag_name == "input" or element.tag_name == "textarea":
6730+ if element.tag_name.lower() in [ "input", "textarea"] :
67206731 self.js_update_text(selector, text, by=by, timeout=timeout)
67216732 else:
67226733 self.set_text_content(selector, text, by=by, timeout=timeout)
@@ -6736,7 +6747,7 @@ def set_text_content(
67366747 element = page_actions.wait_for_element_present(
67376748 self.driver, selector, by, timeout
67386749 )
6739- if element.tag_name == "input" or element.tag_name == "textarea":
6750+ if element.tag_name.lower() in [ "input", "textarea"] :
67406751 self.js_update_text(selector, text, by=by, timeout=timeout)
67416752 return
67426753 orginal_selector = selector
@@ -12250,13 +12261,16 @@ def __demo_mode_highlight_if_active(self, selector, by):
1225012261 selector, by=by, timeout=settings.SMALL_TIMEOUT
1225112262 )
1225212263 try:
12253- scroll_distance = js_utils.get_scroll_distance_to_element(
12254- self.driver, element
12255- )
12256- if abs(scroll_distance) > constants.Values.SSMD:
12257- self.__jquery_slow_scroll_to(selector, by)
12264+ if self.browser != "safari":
12265+ scroll_distance = js_utils.get_scroll_distance_to_element(
12266+ self.driver, element
12267+ )
12268+ if abs(scroll_distance) > constants.Values.SSMD:
12269+ self.__jquery_slow_scroll_to(selector, by)
12270+ else:
12271+ self.__slow_scroll_to_element(element)
1225812272 else:
12259- self.__slow_scroll_to_element(element )
12273+ self.__jquery_slow_scroll_to(selector, by )
1226012274 except (StaleElementReferenceException, ENI_Exception):
1226112275 self.wait_for_ready_state_complete()
1226212276 time.sleep(0.12)
@@ -12290,13 +12304,16 @@ def __highlight_with_assert_success(
1229012304 selector, by=by, timeout=settings.SMALL_TIMEOUT
1229112305 )
1229212306 try:
12293- scroll_distance = js_utils.get_scroll_distance_to_element(
12294- self.driver, element
12295- )
12296- if abs(scroll_distance) > constants.Values.SSMD:
12297- self.__jquery_slow_scroll_to(selector, by)
12307+ if self.browser != "safari":
12308+ scroll_distance = js_utils.get_scroll_distance_to_element(
12309+ self.driver, element
12310+ )
12311+ if abs(scroll_distance) > constants.Values.SSMD:
12312+ self.__jquery_slow_scroll_to(selector, by)
12313+ else:
12314+ self.__slow_scroll_to_element(element)
1229812315 else:
12299- self.__slow_scroll_to_element(element )
12316+ self.__jquery_slow_scroll_to(selector, by )
1230012317 except Exception:
1230112318 self.wait_for_ready_state_complete()
1230212319 time.sleep(0.12)
0 commit comments