[Zope3-checkins] SVN: Zope3/trunk/src/zope/testbrowser/README.txt
Add some docs for using underlying mechanize functionality to
do introspection.
Chris Withers
chris at simplistix.co.uk
Thu Nov 24 11:27:38 EST 2005
Log message for revision 40363:
Add some docs for using underlying mechanize functionality to do introspection.
Changed:
U Zope3/trunk/src/zope/testbrowser/README.txt
-=-
Modified: Zope3/trunk/src/zope/testbrowser/README.txt
===================================================================
--- Zope3/trunk/src/zope/testbrowser/README.txt 2005-11-24 16:16:33 UTC (rev 40362)
+++ Zope3/trunk/src/zope/testbrowser/README.txt 2005-11-24 16:27:37 UTC (rev 40363)
@@ -409,8 +409,31 @@
>>> browser.getControl('Tres')
<ItemControl name='single-select-value' type='select' optionValue='3'>
-Characteristics of controls and subcontrols are discussed below.
+Characteristics of controls and subcontrols are discussed in the
+'Control Objects' section below.
+Introspection to find controls returned by the server
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+testbrowser currently doesn't help much unless you already know the
+controls you will be looking for, however, you can do some
+introspection by utilizing the underlying mechanize functionality.
+
+For example, to find all checkboxes on a page:
+
+ >>> checkboxes = [c.name for c in
+ ... browser.getForm('controls').mech_form.controls
+ ... if c.type=='checkbox']
+ >>> len(checkboxes)
+ 3
+ >>> checkboxes[0:2]
+ ['single-unvalued-checkbox-value', 'single-valued-checkbox-value']
+
+You can then get the actual control as follows:
+
+ >>> browser.getControl(name=checkboxes[2])
+ <ListControl name='multi-checkbox-value' type='checkbox'>
+
Control Objects
~~~~~~~~~~~~~~~
More information about the Zope3-Checkins
mailing list