Extended Monitoring Guide

  • Docs Home
  • Community Home

9. Details on Form Handling

The formvalue (or fv) and submit commands rely on a certain amount of implicit cleverness to do their work. In odd situations, it is difficult to determine which form field formvalue will choose based on your field name, or which form and field submit is going to "click" on.

Example 1

Following is the pseudocode for how formvalue and submit determine which form to use (function 'twill.commands.browser.get_form')::

for each form on page:

if supplied regexp pattern matches the form name, select

if no form name, try converting to an integer N & using N-1 as

an index into the list or forms on the page (for example, form 1 is

the first form on the page).

Example 2

Following is the pseudocode for how formvalue and submit determine which form field to use (function `twill.commands.browser.get_form_field`)::

search current form for control name with exact match to fieldname;

if single (unique) match, select.

if no match, convert fieldname into a number and use as an index, if

possible.

if no match, search current form for control name with regexp match to fieldname;

if single (unique) match, select.

if *still* no match, look for exact matches to submit-button values.

if single (unique) match, select.

Example 3

Following is the pseudocode for `submit`::

if a form was _not_ previously selected by formvalue:

if there is only one form on the page, select it.

otherwise, fail.

if a field is not explicitly named:

if a submit button was "clicked" with formvalue, use it.

otherwise, use the first submit button on the form, if any.

otherwise:

find the field using the same rules as formvalue

finally, if a button has been picked, submit using it;

otherwise, submit without using a button