Skip to content

Commit ad7b412

Browse files
Safari click uses js script for click now
1 parent c24a2ef commit ad7b412

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

dyatel/abstraction/driver_wrapper_abc.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from abc import ABC
4+
from functools import cached_property
45
from typing import List, Union, Any, Tuple
56

67
from dyatel.mixins.objects.cut_box import CutBox
@@ -38,6 +39,33 @@ class DriverWrapperABC(ABC):
3839

3940
browser_name = None
4041

42+
@cached_property
43+
def is_safari(self) -> bool:
44+
"""
45+
Returns the status of whether the current driver is Safari
46+
47+
:return: :class:`bool`
48+
"""
49+
raise NotImplementedError()
50+
51+
@cached_property
52+
def is_chrome(self) -> bool:
53+
"""
54+
Returns the status of whether the current driver is Chrome
55+
56+
:return: :class:`bool`
57+
"""
58+
raise NotImplementedError()
59+
60+
@cached_property
61+
def is_firefox(self) -> bool:
62+
"""
63+
Returns the status of whether the current driver is Firefox
64+
65+
:return: :class:`bool`
66+
"""
67+
raise NotImplementedError()
68+
4169
def quit(self, silent: bool = False, trace_path: str = 'trace.zip'):
4270
"""
4371
Quit the driver instance

dyatel/base/driver_wrapper.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from functools import cached_property
34
from typing import Union, Type, List, Tuple, Any, Optional
45

56
from PIL import Image
@@ -154,6 +155,33 @@ def __init__(
154155
self.is_desktop = False
155156
self.is_mobile = True
156157

158+
@cached_property
159+
def is_safari(self) -> bool:
160+
"""
161+
Returns the status of whether the current driver is Safari
162+
163+
:return: :class:`bool`
164+
"""
165+
return self.browser_name.lower() == 'safari'
166+
167+
@cached_property
168+
def is_chrome(self) -> bool:
169+
"""
170+
Returns the status of whether the current driver is Chrome
171+
172+
:return: :class:`bool`
173+
"""
174+
return self.browser_name.lower() == 'chrome'
175+
176+
@cached_property
177+
def is_firefox(self) -> bool:
178+
"""
179+
Returns the status of whether the current driver is Firefox
180+
181+
:return: :class:`bool`
182+
"""
183+
return self.browser_name.lower() == 'firefox'
184+
157185
def quit(self, silent: bool = False, trace_path: str = 'trace.zip'):
158186
"""
159187
Quit the driver instance

dyatel/dyatel_sel/core/core_element.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from dyatel.abstraction.element_abc import ElementABC
2323
from dyatel.dyatel_sel.sel_utils import ActionChains
24-
from dyatel.js_scripts import get_element_size_js, get_element_position_on_screen_js
24+
from dyatel.js_scripts import get_element_size_js, get_element_position_on_screen_js, js_click
2525
from dyatel.keyboard_keys import KeyboardKeys
2626
from dyatel.mixins.objects.location import Location
2727
from dyatel.mixins.objects.scrolls import ScrollTo, ScrollTypes, scroll_into_view_blocks
@@ -102,7 +102,13 @@ def click(self, force_wait: bool = True, *args, **kwargs) -> CoreElement:
102102
start_time = time.time()
103103
while time.time() - start_time < HALF_WAIT_EL:
104104
try:
105-
self.wait_enabled(silent=True).element.click()
105+
element = self.wait_enabled(silent=True).element
106+
107+
if self.driver_wrapper.is_safari:
108+
self.execute_script(js_click)
109+
else:
110+
element.click()
111+
106112
return self
107113
except (
108114
SeleniumElementNotInteractableException,
@@ -359,7 +365,7 @@ def text(self) -> str:
359365
"""
360366
element = self._get_element(wait=self.wait_availability)
361367

362-
if self.driver_wrapper.browser_name.lower() == 'safari':
368+
if self.driver_wrapper.is_safari:
363369
return element.get_attribute('innerText')
364370

365371
return element.text

dyatel/js_scripts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
get_inner_height_js = 'return window.innerHeight'
22
get_inner_width_js = 'return window.innerWidth'
3+
js_click = 'arguments[0].click();'
34

45
get_element_position_on_screen_js = """
56
function getPositionOnScreen(elem) {

0 commit comments

Comments
 (0)