diff --git a/common/src/web/javascriptPage.html b/common/src/web/javascriptPage.html index 3fdb38a46f4c1..c8af8c95b88b0 100644 --- a/common/src/web/javascriptPage.html +++ b/common/src/web/javascriptPage.html @@ -249,7 +249,7 @@

Type Stuff

Focusable. Will hide when focus is lost. -
+
Click actions delayed by 3000ms:
diff --git a/py/selenium/webdriver/support/expected_conditions.py b/py/selenium/webdriver/support/expected_conditions.py index f418a214e3b49..25352515790c7 100644 --- a/py/selenium/webdriver/support/expected_conditions.py +++ b/py/selenium/webdriver/support/expected_conditions.py @@ -386,6 +386,27 @@ def _predicate(_): return _predicate +def elements_not_overlapping(element1: WebElement, element2:WebElement) -> Callable[[Any], bool]: + """An Expectation for checking that two elements do not overlap on the DOM + + elements are WebElement objects + """ + + def _predicate(_): + if staleness_of(element1): + return True + if staleness_of(element2): + return True + + rect1 = element1.rect + rect2 = element2.rect + return (rect1['x'] + rect1['width'] < rect2['x'] or + rect2['x'] + rect2['width'] < rect1['x'] or + rect1['y'] + rect1['height'] < rect2['y'] or + rect2['y'] + rect2['height'] < rect1['y']) + + return _predicate + def element_to_be_selected(element: WebElement) -> Callable[[Any], bool]: """An expectation for checking the selection is selected. diff --git a/py/test/selenium/webdriver/common/webdriverwait_tests.py b/py/test/selenium/webdriver/common/webdriverwait_tests.py index 14019d185e8b0..cd298a6d77652 100644 --- a/py/test/selenium/webdriver/common/webdriverwait_tests.py +++ b/py/test/selenium/webdriver/common/webdriverwait_tests.py @@ -282,6 +282,23 @@ def test_expected_condition_element_to_be_clickable(driver, pages): WebDriverWait(driver, 4.5).until(EC.invisibility_of_element_located((By.ID, "clickToHide"))) assert element.is_displayed() is False +def test_expected_condition_elements_not_overlapping(driver, pages): + pages.load("javascriptPage.html") + element1 = driver.find_element(By.ID, 'keyUp') + element2 = driver.find_element(By.ID, 'keyDown') + WebDriverWait(driver, 1).until(EC.elements_not_overlapping(element1,element2)) + clickToShow = driver.find_element(By.ID, 'clickToShow') + clickToShow.click() + WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.ID, "clickToHide"))) + element1 = driver.find_element(By.ID, 'clickToHide') + element2 = driver.find_element(By.ID, 'clickToShowParent') + with pytest.raises(TimeoutException): + WebDriverWait(driver, 1).until(EC.elements_not_overlapping(element1,element2)) + element1.click() + WebDriverWait(driver, 5).until(EC.elements_not_overlapping(element1,element2)) + assert element1.is_displayed() is False + + def test_expected_condition_staleness_of(driver, pages): pages.load("dynamicallyModifiedPage.html")