Latest Version: 0.9.6.2

Form

This object represents a form that has been found in a page. This has a couple useful attributes:

text:
the full HTML of the form.
action:
the relative URI of the action.
method:
the method (e.g., 'GET').
id:
the id, or None if not given.
fields:
a dictionary of fields, each value is a list of fields by that name. <input type="radio"> and <select> are both represented as single fields with multiple options.

Methods

f __getitem__(self, name) ...

Get the named field object (ambiguity is an error).

f __init__(self, response, text) ...

f __setitem__(self, name, value) ...

Set the value of the named field. If there is 0 or multiple fields by that name, it is an error.

Setting the value of a <select> selects the given option (and confirms it is an option). Setting radio fields does the same. Checkboxes get boolean values. You cannot set hidden fields or buttons.

Use .set() if there is any ambiguity and you must provide an index.

f get(self, name, index=None, default=<class 'paste.fixture.NoDefault'>) ...

Get the named/indexed field object, or default if no field is found.

f select(self, name, value, index=None) ...

Like .set(), except also confirms the target is a <select>.

f set(self, name, value, index=None) ...

Set the given name, using index to disambiguate.

f submit(self, name=None, index=None, **args) ...

Submits the form. If name is given, then also select that button (using index to disambiguate)``.

Any extra keyword arguments are passed to the .get() or .post() method.

f submit_fields(self, name=None, index=None) ...

Return a list of [(name, value), ...] for the current state of the form.

See the source for more information.

Top