Merge lp:~elopio/selenium-simple-test/clear-using-keys into lp:selenium-simple-test

Proposed by Leo Arias
Status: Merged
Merge reported by: Corey Goldberg
Merged at revision: not available
Proposed branch: lp:~elopio/selenium-simple-test/clear-using-keys
Merge into: lp:selenium-simple-test
Diff against target: 94 lines (+54/-1)
5 files modified
src/sst/actions.py (+2/-1)
src/sst/selftests/yui.py (+5/-0)
src/testproject/simple/views.py (+3/-0)
src/testproject/templates/yui.html (+43/-0)
src/testproject/urls.py (+1/-0)
To merge this branch: bzr merge lp:~elopio/selenium-simple-test/clear-using-keys
Reviewer Review Type Date Requested Status
Corey Goldberg (community) Approve
Review via email: mp+77636@code.launchpad.net

This proposal supersedes a proposal from 2011-09-22.

Description of the change

Workaround to clear a textfield that has a default value, using the backspace key. (LP: #856107)

The clear function causes the onchange event to fire, setting the default value on the textfield just after clearing it. The send_keys function doesn't launch the onchange event, so it's possible to clear the textfield even if it has a default value.

To post a comment you must log in.
Revision history for this message
Corey Goldberg (coreygoldberg) wrote : Posted in a previous version of this proposal

needs a selftest.

review: Needs Fixing
Revision history for this message
Corey Goldberg (coreygoldberg) wrote :

looks good.
there are conflicts with this branch and trunk. I am resolving them and will push to trunk.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/sst/actions.py'
2--- src/sst/actions.py 2011-09-27 23:48:16 +0000
3+++ src/sst/actions.py 2011-09-30 03:22:24 +0000
4@@ -383,7 +383,8 @@
5 `check=False`."""
6 _print('Writing to textfield %r with text %r' % (id_or_elem, new_text))
7 textfield = is_textfield(id_or_elem)
8- textfield.clear()
9+ while textfield.get_attribute('value'):
10+ textfield.send_keys(keys.Keys().BACK_SPACE)
11 textfield.send_keys(new_text)
12 if not check:
13 return
14
15=== added file 'src/sst/selftests/yui.py'
16--- src/sst/selftests/yui.py 1970-01-01 00:00:00 +0000
17+++ src/sst/selftests/yui.py 2011-09-30 03:22:24 +0000
18@@ -0,0 +1,5 @@
19+from sst.actions import *
20+
21+goto('/yui')
22+
23+textfield_write('text_with_default_value', '25', check=True)
24
25=== modified file 'src/testproject/simple/views.py'
26--- src/testproject/simple/views.py 2011-09-25 17:36:08 +0000
27+++ src/testproject/simple/views.py 2011-09-30 03:22:24 +0000
28@@ -31,3 +31,6 @@
29
30 def frame_b(request):
31 return render_to_response('frame_b.html')
32+
33+def yui(request):
34+ return render_to_response('yui.html')
35
36=== added file 'src/testproject/templates/yui.html'
37--- src/testproject/templates/yui.html 1970-01-01 00:00:00 +0000
38+++ src/testproject/templates/yui.html 2011-09-30 03:22:24 +0000
39@@ -0,0 +1,43 @@
40+<html>
41+<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
42+<head>
43+ <title>Page using the YUI library</title>
44+</head>
45+
46+<body>
47+
48+ <form>
49+ <label for='text_with_default_value'>Text field with default value</label>
50+ <input id='text_with_default_value' value='1'>
51+ </form>
52+
53+<script type="text/javascript">
54+
55+/**
56+ * Returns true if the input is an int.
57+ *
58+ * @params input The value to check.
59+ * @return true if the input is an int. Otherwise, false.
60+ */
61+function is_int(input) {
62+ return !isNaN(input) && parseInt(input) == input;
63+}
64+
65+/**
66+ * Use YUI to listen to the on change event of the text input, and return to
67+ * the default value if it's not a number greater than 0.
68+ */
69+YUI().use('node', function(Y) {
70+ var input = Y.one('#text_with_default_value');
71+
72+ input.on('change', function(e) {
73+ var value = input.get('value');
74+
75+ if (value == '' || !is_int(value) || value < 1) {
76+ input.set('value', 1);
77+ }
78+ });
79+});
80+</script>
81+</body>
82+</html>
83
84=== modified file 'src/testproject/urls.py'
85--- src/testproject/urls.py 2011-09-25 17:36:08 +0000
86+++ src/testproject/urls.py 2011-09-30 03:22:24 +0000
87@@ -15,6 +15,7 @@
88 (r'popup', 'simple.views.popup'),
89 (r'frame_a', 'simple.views.frame_a'),
90 (r'frame_b', 'simple.views.frame_b'),
91+ (r'yui', 'simple.views.yui'),
92 (r'', 'simple.views.index'),
93
94 # Uncomment the admin/doc line below and add 'django.contrib.admindocs'

Subscribers

People subscribed via source and target branches