tests: functional: Handle obscured elements when submitting forms

In some cases in the backup page, when trying to restore a backup, the button is
obscured and trying to click it fails. Handle such situations by scrolling the
element into view first and try to click on the element again. Ensure that our
navigation header does not obscure the element when scrolling it into view.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2024-07-29 15:54:38 -04:00
1 parent 170685c806
commit dd6b865de6
1 file changed
+12 -1
+12 -1
View File
@@ -203,6 +203,17 @@ def download_file_outside_browser(url):
###########################
# Form handling utilities #
###########################
def click(browser, element):
"""Click an element after scrolling it into view considering header."""
try:
element.click()
except ElementClickInterceptedException:
script = 'arguments[0].style.scrollMarginTop = "4.3125rem";' \
'arguments[0].scrollIntoView(true);'
browser.execute_script(script, element._element)
element.click()
def submit(browser, element=None, form_class=None, expected_url=None):
"""Submit a specific form in the current page and wait for page change."""
if not (element or form_class):
@@ -210,7 +221,7 @@ def submit(browser, element=None, form_class=None, expected_url=None):
with wait_for_page_update(browser, expected_url=expected_url):
if element:
element.click()
click(browser, element)
elif form_class:
browser.find_by_css(
'.{} input[type=submit]'.format(form_class)).click()