@@ -291,20 +291,19 @@ def click(
291
291
pre_action_url = self.driver.current_url
292
292
pre_window_count = len(self.driver.window_handles)
293
293
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
+ ):
296
300
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)
302
301
else:
303
302
href = None
304
303
new_tab = False
305
304
onclick = None
306
305
try:
307
- if self.headless and element.tag_name == "a":
306
+ if self.headless and element.tag_name.lower() == "a":
308
307
# Handle a special case of opening a new tab (headless)
309
308
href = element.get_attribute("href").strip()
310
309
onclick = element.get_attribute("onclick")
@@ -343,11 +342,8 @@ def click(
343
342
self.__scroll_to_element(element, selector, by)
344
343
except Exception:
345
344
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)
351
347
else:
352
348
element.click()
353
349
except ENI_Exception:
@@ -364,7 +360,7 @@ def click(
364
360
new_tab = False
365
361
onclick = None
366
362
try:
367
- if element.tag_name == "a":
363
+ if element.tag_name.lower() == "a":
368
364
# Handle a special case of opening a new tab (non-headless)
369
365
href = element.get_attribute("href").strip()
370
366
onclick = element.get_attribute("onclick")
@@ -1449,10 +1445,11 @@ def get_text(self, selector, by="css selector", timeout=None):
1449
1445
try:
1450
1446
element_text = element.text
1451
1447
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"]:
1456
1453
element_text = element.get_property("value")
1457
1454
except (StaleElementReferenceException, ENI_Exception):
1458
1455
self.wait_for_ready_state_complete()
@@ -1462,8 +1459,11 @@ def get_text(self, selector, by="css selector", timeout=None):
1462
1459
)
1463
1460
element_text = element.text
1464
1461
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"]:
1467
1467
element_text = element.get_property("value")
1468
1468
return element_text
1469
1469
@@ -2219,9 +2219,6 @@ def hover_and_click(
2219
2219
if self.mobile_emulator:
2220
2220
# On mobile, click to hover the element
2221
2221
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.")
2225
2222
else:
2226
2223
page_actions.hover_element(self.driver, dropdown_element)
2227
2224
except Exception:
@@ -2264,6 +2261,12 @@ def hover_and_click(
2264
2261
)
2265
2262
):
2266
2263
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
2267
2270
if self.demo_mode:
2268
2271
if self.driver.current_url != pre_action_url:
2269
2272
self.__demo_mode_pause_if_active()
@@ -2625,10 +2628,11 @@ def get_select_options(
2625
2628
raise Exception("The attribute must be in %s" % allowed_attributes)
2626
2629
selector, by = self.__recalculate_selector(selector, by)
2627
2630
element = self.wait_for_element(selector, by=by, timeout=timeout)
2628
- if element.tag_name != "select":
2631
+ if element.tag_name.lower() != "select":
2629
2632
raise Exception(
2630
2633
'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()
2632
2636
)
2633
2637
if by != "css selector":
2634
2638
selector = self.convert_to_css_selector(selector, by=by)
@@ -2712,9 +2716,13 @@ def load_html_string(self, html_string, new_page=True):
2712
2716
html_string = html_string.replace("\\ ", " ")
2713
2717
2714
2718
if new_page:
2715
- self.open("data:text/html,")
2719
+ self.open("data:text/html,<head></head><body></body> ")
2716
2720
inner_head = """document.getElementsByTagName("head")[0].innerHTML"""
2717
2721
inner_body = """document.getElementsByTagName("body")[0].innerHTML"""
2722
+ try:
2723
+ self.wait_for_element_present("body", timeout=1)
2724
+ except Exception:
2725
+ pass
2718
2726
if not found_body:
2719
2727
self.execute_script('''%s = \"%s\"''' % (inner_body, html_string))
2720
2728
elif found_body and not found_head:
@@ -5097,13 +5105,16 @@ def slow_scroll_to(self, selector, by="css selector", timeout=None):
5097
5105
original_selector, by=original_by, timeout=timeout
5098
5106
)
5099
5107
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)
5105
5116
else:
5106
- self.__slow_scroll_to_element(element )
5117
+ self.__jquery_slow_scroll_to(selector, by )
5107
5118
except Exception:
5108
5119
self.wait_for_ready_state_complete()
5109
5120
time.sleep(0.12)
@@ -6716,7 +6727,7 @@ def set_text(self, selector, text, by="css selector", timeout=None):
6716
6727
element = page_actions.wait_for_element_present(
6717
6728
self.driver, selector, by, timeout
6718
6729
)
6719
- if element.tag_name == "input" or element.tag_name == "textarea":
6730
+ if element.tag_name.lower() in [ "input", "textarea"] :
6720
6731
self.js_update_text(selector, text, by=by, timeout=timeout)
6721
6732
else:
6722
6733
self.set_text_content(selector, text, by=by, timeout=timeout)
@@ -6736,7 +6747,7 @@ def set_text_content(
6736
6747
element = page_actions.wait_for_element_present(
6737
6748
self.driver, selector, by, timeout
6738
6749
)
6739
- if element.tag_name == "input" or element.tag_name == "textarea":
6750
+ if element.tag_name.lower() in [ "input", "textarea"] :
6740
6751
self.js_update_text(selector, text, by=by, timeout=timeout)
6741
6752
return
6742
6753
orginal_selector = selector
@@ -12250,13 +12261,16 @@ def __demo_mode_highlight_if_active(self, selector, by):
12250
12261
selector, by=by, timeout=settings.SMALL_TIMEOUT
12251
12262
)
12252
12263
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)
12258
12272
else:
12259
- self.__slow_scroll_to_element(element )
12273
+ self.__jquery_slow_scroll_to(selector, by )
12260
12274
except (StaleElementReferenceException, ENI_Exception):
12261
12275
self.wait_for_ready_state_complete()
12262
12276
time.sleep(0.12)
@@ -12290,13 +12304,16 @@ def __highlight_with_assert_success(
12290
12304
selector, by=by, timeout=settings.SMALL_TIMEOUT
12291
12305
)
12292
12306
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)
12298
12315
else:
12299
- self.__slow_scroll_to_element(element )
12316
+ self.__jquery_slow_scroll_to(selector, by )
12300
12317
except Exception:
12301
12318
self.wait_for_ready_state_complete()
12302
12319
time.sleep(0.12)
0 commit comments