diff --git a/py/selenium/webdriver/common/timeouts.py b/py/selenium/webdriver/common/timeouts.py index 82ce537e40cee..0f7f78e2317fe 100644 --- a/py/selenium/webdriver/common/timeouts.py +++ b/py/selenium/webdriver/common/timeouts.py @@ -37,6 +37,27 @@ class JSONTimeouts(TypedDict, total=False): JSONTimeouts = Dict[str, int] +class _TimeoutsDescriptor: + """TimeoutsDescriptor which gets and sets value of below attributes: + + _implicit _timeout + _page_load + _script + + This does not set the value on the remote end + """ + + def __init__(self, name): + self.name = name + + def __get__(self, obj, cls) -> float: + return getattr(obj, self.name) / 1000 + + def __set__(self, obj, value) -> None: + converted_value = getattr(obj, "_convert")(value) + setattr(obj, self.name, converted_value) + + class Timeouts: def __init__(self, implicit_wait: float = 0, page_load: float = 0, script: float = 0) -> None: """Create a new Timeout object. @@ -53,53 +74,57 @@ def __init__(self, implicit_wait: float = 0, page_load: float = 0, script: float self.page_load = page_load self.script = script - @property - def implicit_wait(self) -> float: - """Return the value for the implicit wait. - - This does not return the value on the remote end - """ - return self._implicit_wait / 1000 - - @implicit_wait.setter - def implicit_wait(self, _implicit_wait: float) -> None: - """Sets the value for the implicit wait. - - This does not set the value on the remote end - """ - self._implicit_wait = self._convert(_implicit_wait) - - @property - def page_load(self) -> float: - """Return the value for the page load wait. - - This does not return the value on the remote end - """ - return self._page_load / 1000 - - @page_load.setter - def page_load(self, _page_load: float) -> None: - """Sets the value for the page load wait. - - This does not set the value on the remote end - """ - self._page_load = self._convert(_page_load) - - @property - def script(self) -> float: - """Return the value for the script wait. - - This does not return the value on the remote end - """ - return self._script / 1000 - - @script.setter - def script(self, _script: float) -> None: - """Sets the value for the script wait. - - This does not set the value on the remote end - """ - self._script = self._convert(_script) + # Creating descriptor objects + implicit_wait = _TimeoutsDescriptor("_implicit_wait") + """Sets and Gets the value of the implicit_timeout: + + This does not set the value on the remote end. + + Usage + ----- + - Get + - `self.implicit_timeout` + - Set + - `self.implicit_timeout` = `value` + + Parameters + ---------- + `value`: `float` + """ + + page_load = _TimeoutsDescriptor("_page_load") + """Sets and Gets the value of page load wait: + + This does not set the value on the remote end. + + Usage + ----- + - Get + - `self.page_load` + - Set + - `self.page_load` = `value` + + Parameters + ---------- + `value`: `float` + """ + + script = _TimeoutsDescriptor("_script") + """Sets and Gets the value of script wait: + + This does not set the value on the remote end. + + Usage + ------ + - Get + - `self.script` + - Set + - `self.script` = `value` + + Parameters + ----------- + `value`: `float` + """ def _convert(self, timeout: float) -> int: if isinstance(timeout, (int, float)):