Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #20 from Gagnavarslan/master-clear-input
Browse files Browse the repository at this point in the history
Cross-browser clear input field
  • Loading branch information
arnlaugsson authored Jul 21, 2016
2 parents 75d364c + c06e7a3 commit 609acdd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/sst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#


__version__ = '0.2.8dev-4'
__version__ = '0.2.9'

DEVSERVER_PORT = 8120 # django devserver for internal acceptance tests

Expand Down
19 changes: 14 additions & 5 deletions src/sst/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,26 @@ def assert_textfield(id_or_elem):


def on_mac():
# This only works if the OS running the tests is the same running
# the browser.
return sys.platform == 'darwin'


def send_keys_select_all(textfield):
modifier = keys.Keys().COMMAND if on_mac() else keys.Keys().CONTROL
modifier = keys.Keys.COMMAND if on_mac() else keys.Keys.CONTROL
textfield.send_keys(modifier, 'a')


def clear_textfield(textfield):
# clear field with send_keys(), don't use clear() (see
# http://code.google.com/p/selenium/issues/detail?id=214 for rationale)
send_keys_select_all(textfield)
textfield.send_keys(keys.Keys.DELETE)
if textfield.get_attribute('value') != '':
# for when send_keys does not work, e.g. PhantomJS
textfield.clear()


def write_textfield(id_or_elem, new_text, check=True, clear=True):
"""Write a text into a text field.
Expand All @@ -559,11 +571,8 @@ def write_textfield(id_or_elem, new_text, check=True, clear=True):
% (_element_to_string(textfield), new_text)
logger.debug(msg)

# clear field with send_keys(), don't use clear() (see
# http://code.google.com/p/selenium/issues/detail?id=214 for rationale)
if clear:
send_keys_select_all(textfield)
textfield.send_keys(keys.Keys().DELETE)
clear_textfield(textfield)

if isinstance(new_text, unicode):
textfield.send_keys(new_text)
Expand Down

0 comments on commit 609acdd

Please sign in to comment.