Skip to content

add keyword input_text_into_prompt #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from Jul 21, 2015
Merged
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Release Notes
=============

- Added new keyword Input Text Into Prompt [boakley][ekasteel]

1.7.2
----------------
- Fixed an error where regular functions were not able to be used as a custom locator
Expand Down
9 changes: 9 additions & 0 deletions src/Selenium2Library/keywords/_formelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ def input_text(self, locator, text):
self._info("Typing text '%s' into text field '%s'" % (text, locator))
self._input_text_into_text_field(locator, text)

def input_text_into_prompt(self, text):
"""Types the given `text` into alert box. """
alert = None
try:
alert = self._current_browser().switch_to_alert()
alert.send_keys(text)
except WebDriverException:
raise RuntimeError('There were no alerts')

def page_should_contain_textfield(self, locator, message='', loglevel='INFO'):
"""Verifies text field identified by `locator` is found from current page.

Expand Down
13 changes: 13 additions & 0 deletions test/acceptance/keywords/input_text_into_prompt.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*Setting*
Variables variables.py
Resource ../resource.robot
Test Setup Go To Page "javascript/alert_prompt.html"


*Test Cases*

Verify Input Text into Prompt
[Documentation] Typing name into prompt
Click Element css=button
Input Text Into Prompt myname
Get Alert Message
23 changes: 23 additions & 0 deletions test/resources/html/javascript/alert_prompt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<body>

<p>Click the button to demonstrate the prompt box.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
var person = prompt("Please enter your name", "Harry Potter");

if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?";
}
}
</script>

</body>
</html>