Skip to content

Commit 0312dac

Browse files
authored
Add wait for element enabled (#42)
1 parent c4159ec commit 0312dac

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

Examples/wait-for-demo.robot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,14 @@ Demo wait for location contains
6363
Go To ${HOME_PAGE_URL}/docs.html
6464
Switch Window NEW
6565
Wait Until Location Contains docs.html
66+
67+
Demo wait for element is enabled
68+
${HEADLESS} Get variable value ${HEADLESS} ${False}
69+
&{options} = create dictionary headless=${HEADLESS}
70+
Open browser ${HOME_PAGE_URL} options=${options}
71+
Go To ${HOME_PAGE_URL}/form.html
72+
Wait Until Element Is Enabled id=disable_button
73+
Click Element id=disable_button
74+
Wait Until Page Contains Login succeeded
75+
76+

PuppeteerLibrary/keywords/waiting.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,12 @@ def wait_until_location_does_not_contains(self, expected, timeout=None):
192192
The `expected` argument contains the expected value must not in url.
193193
"""
194194
return self.loop.run_until_complete(self.async_func.wait_until_location_does_not_contains_async(expected, timeout))
195+
196+
@keyword
197+
def wait_until_element_is_enabled(self, selenium_locator, timeout=None):
198+
"""
199+
Waits until the specific element is Enabled.
200+
201+
"""
202+
return self.loop.run_until_complete(
203+
self.async_func.wait_until_element_is_enabled_async(selenium_locator, timeout))

PuppeteerLibrary/keywords/waiting_async.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ async def validate_url_not_contains_text():
109109
validate_url_not_contains_text,
110110
self.timestr_to_secs_for_default_timeout(timeout))
111111

112+
@keyword
113+
async def wait_until_element_is_enabled_async(self, selenium_locator, timeout=None):
114+
async def validate_is_enabled():
115+
element = await self.ctx.get_current_page().querySelector_with_selenium_locator(selenium_locator)
116+
is_disabled = await (await element.getProperty('disabled')).jsonValue()
117+
return is_disabled == False
118+
return await self._wait_until_worker(
119+
validate_is_enabled,
120+
self.timestr_to_secs_for_default_timeout(timeout),
121+
'Element '+selenium_locator+' was not enabled.')
122+
112123
async def _wait_until_worker(self, condition, timeout, error=None):
113124
max_time = time.time() + timeout
114125
not_found = None

demoapp/html/form.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
<option value="opel">Opel</option>
1414
<option value="audi">Audi</option>
1515
</select>
16-
</div>
16+
</div>
17+
<button id="disable_button" disabled onclick="goto();">disable button</button>
18+
19+
<script>
20+
setTimeout(function(){
21+
document.getElementById('disable_button').disabled = false; }
22+
, 2000);
23+
24+
function goto() {
25+
window.location = "welcome.html";
26+
}
27+
</script>
1728
</body>
1829
</html>

0 commit comments

Comments
 (0)