From 4c581e29ce1e15d0b6ff5e3bba6b00855ba87557 Mon Sep 17 00:00:00 2001 From: Viktor Date: Wed, 6 Nov 2019 23:49:51 +0200 Subject: [PATCH] Added wait for element to be in viewport for element. --- se_wrapper/element/element_waits.py | 13 +++++++++++++ se_wrapper/element/expectations.py | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/se_wrapper/element/element_waits.py b/se_wrapper/element/element_waits.py index 4994aff..51fae9c 100644 --- a/se_wrapper/element/element_waits.py +++ b/se_wrapper/element/element_waits.py @@ -96,3 +96,16 @@ def not_present_in_dom(self, timeout: TimeoutType): if timeout: timeout_ = timeout return self._webdriver.wait_for.no_element_in_dom(self._web_element, timeout_) + + def to_be_on_the_screen(self, timeout: TimeoutType): + """True for an element is present on the screen (inside the viewport). + Checks if element's coordinates match viewport height and width. + Different from `to_be_visible` as `to_be_visible` checks element has size > 1px + and display is not `:none`. + :param timeout: equal to the self.timeout if other not passed. + + """ + timeout_ = self._timeout + if timeout: + timeout_ = timeout + return self._webdriver.wait_for.element_to_be_in_viewport(self._web_element, timeout_) diff --git a/se_wrapper/element/expectations.py b/se_wrapper/element/expectations.py index b1c99d9..1a532a9 100644 --- a/se_wrapper/element/expectations.py +++ b/se_wrapper/element/expectations.py @@ -126,3 +126,17 @@ def not_present_in_dom(self, timeout: TimeoutType): return self._webdriver.wait_for.no_element_in_dom(self._web_element, timeout_) except TimeoutException: return False + + def to_be_on_the_screen(self, timeout: TimeoutType): + """True for an element is present on the screen (inside the viewport). + False if element's coordinates don't match viewport height and width. + :param timeout: equal to the self.timeout if other not passed. + + """ + timeout_ = self._timeout + if timeout: + timeout_ = timeout + try: + return self._webdriver.wait_for.element_to_be_in_viewport(self._web_element, timeout_) + except TimeoutException: + return False