Hi, I've been developing tutorialtest ( http://grahamstratton.org/straightornamental/entries/z3ctutorialtest ), and hit on a couple of issues with zc.testbrowser.real. These may be Firefox bugs, but I know very little about DOM stuff, and my Javascript books are 11,000 miles away.

My web application allows the user to toggle the visibility of some forms. I found that setting the value of form elements in forms that had at one point been hidden failed. It turns out that setAttribute('value', ...) stops working, as shown in the REPL session below.

Initally it's possible to set values quite happily (note that element.value consistently gives the value that is displayed and submitted. element.getAttribute(value) consistently gives the value set with setAttribute; the problem is when these differ):

repl> content .document.getElementById('form.name').setAttribute('value','three')
repl> content.document.getElementById('form.name').value
"three"
repl> content .document.getElementById('form.name').setAttribute('value','four')
repl> content.document.getElementById('form.name').value
"four"

Now if we hide and show the element (or any enclosing element), setAttribute stops working:

repl> content.document.getElementById('form.name').style.display
""
repl> content.document.getElementById('form.name').style.display = 'none'
"none"
repl> content.document.getElementById('form.name').style.display = ''
""
repl> content .document.getElementById('form.name').setAttribute('value','three')
repl> content.document.getElementById('form.name').value
"four"


I edited real.py to read and write the property directly rather than using (s/g)etAttribute for all elements except file controls. After that, all the tests still pass. I suspect this is not good practice, but it makes it work. Should I check in this patch, or is there a better fix?

Many thanks,

Graham


Patch against MozLab 0.1.9 branch of zc.testbrowser:

Index: src/zc/testbrowser/real.py
===================================================================
--- src/zc/testbrowser/real.py  (revision 88569)
+++ src/zc/testbrowser/real.py  (working copy)
@@ -399,7 +399,7 @@
     def value():

         def fget(self):
-            if self.type == 'textarea':
+            if self.type != 'file':
                 return self.browser.execute('tb_tokens[%s].value'
                                             % self.token)
             return self.browser.execute(
@@ -419,7 +419,7 @@
                 self.mech_control.items[0].selected = bool(value)
             else:
                 self.browser.execute(
-                    'tb_tokens[%s].setAttribute("value", %s)' %(
+                    'tb_tokens[%s].value = %s' %(
                     self.token, simplejson.dumps(value)))
         return property(fget, fset)


_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )

Reply via email to