From 78ca9621d801d53d8635c39a21476706a2b9ffe4 Mon Sep 17 00:00:00 2001 From: atthaboons Date: Fri, 28 Aug 2020 15:28:00 +0700 Subject: [PATCH] Add wait for element enabled --- Examples/wait-for-demo.robot | 11 +++++++++++ PuppeteerLibrary/keywords/waiting.py | 9 +++++++++ PuppeteerLibrary/keywords/waiting_async.py | 11 +++++++++++ demoapp/html/form.html | 13 ++++++++++++- 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Examples/wait-for-demo.robot b/Examples/wait-for-demo.robot index 5c27b15..50666ce 100644 --- a/Examples/wait-for-demo.robot +++ b/Examples/wait-for-demo.robot @@ -63,3 +63,14 @@ Demo wait for location contains Go To ${HOME_PAGE_URL}/docs.html Switch Window NEW Wait Until Location Contains docs.html + +Demo wait for element is enabled + ${HEADLESS} Get variable value ${HEADLESS} ${False} + &{options} = create dictionary headless=${HEADLESS} + Open browser ${HOME_PAGE_URL} options=${options} + Go To ${HOME_PAGE_URL}/form.html + Wait Until Element Is Enabled id=disable_button + Click Element id=disable_button + Wait Until Page Contains Login succeeded + + \ No newline at end of file diff --git a/PuppeteerLibrary/keywords/waiting.py b/PuppeteerLibrary/keywords/waiting.py index fed4067..44dd4bb 100644 --- a/PuppeteerLibrary/keywords/waiting.py +++ b/PuppeteerLibrary/keywords/waiting.py @@ -192,3 +192,12 @@ def wait_until_location_does_not_contains(self, expected, timeout=None): The `expected` argument contains the expected value must not in url. """ return self.loop.run_until_complete(self.async_func.wait_until_location_does_not_contains_async(expected, timeout)) + + @keyword + def wait_until_element_is_enabled(self, selenium_locator, timeout=None): + """ + Waits until the specific element is Enabled. + + """ + return self.loop.run_until_complete( + self.async_func.wait_until_element_is_enabled_async(selenium_locator, timeout)) diff --git a/PuppeteerLibrary/keywords/waiting_async.py b/PuppeteerLibrary/keywords/waiting_async.py index d98d0f4..022c309 100644 --- a/PuppeteerLibrary/keywords/waiting_async.py +++ b/PuppeteerLibrary/keywords/waiting_async.py @@ -109,6 +109,17 @@ async def validate_url_not_contains_text(): validate_url_not_contains_text, self.timestr_to_secs_for_default_timeout(timeout)) + @keyword + async def wait_until_element_is_enabled_async(self, selenium_locator, timeout=None): + async def validate_is_enabled(): + element = await self.ctx.get_current_page().querySelector_with_selenium_locator(selenium_locator) + is_disabled = await (await element.getProperty('disabled')).jsonValue() + return is_disabled == False + return await self._wait_until_worker( + validate_is_enabled, + self.timestr_to_secs_for_default_timeout(timeout), + 'Element '+selenium_locator+' was not enabled.') + async def _wait_until_worker(self, condition, timeout, error=None): max_time = time.time() + timeout not_found = None diff --git a/demoapp/html/form.html b/demoapp/html/form.html index 5109fef..2bc9ee3 100644 --- a/demoapp/html/form.html +++ b/demoapp/html/form.html @@ -13,6 +13,17 @@ - + + + + \ No newline at end of file