cobrateam/splinter — Issue #111: Return tag-specific objects in DriverAPI.find_* methods
Author: turicas
Created: 2011-10-09 18:44:05+00:00
State: open

`DriverAPI.find_*` methods __must return tag-specific objects__!

Now, for example, in Firefox driver, all `.find_*` methods returns a `WebDriverElement` instance (which is inherited on `DriverAPI`) -- and this instance have __a lot of garbage__.

The code below:

from splinter.browser import Browser
browser = Browser()
browser.visit('http://www.google.com/')
my_form = browser.find_by_tag('form').first
print dir(my_form)

actually prints:

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__metaclass__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_element', '_get_value', '_set_value', 'action_chains', 'check', 'checked', 'click', 'double_click', 'drag_and_drop', 'fill', 'find_by_css', 'find_by_id', 'find_by_name', 'find_by_tag', 'find_by_value', 'find_by_xpath', 'mouse_out', 'mouse_over', 'mouseout', 'mouseover', 'parent', 'right_click', 'selected', 'text', 'type', 'uncheck', 'value', 'visible']

but __we don't need__ the method `check`, the attribute `checked` (and many others) for this element. It is a form element, not a generic one. It is also ambiguous since the method `find_by_tag` in a *form element* finds an element by tag *in the whole page*.

So I propose specialized methods and attributes. For now, I think the most important ones are:
- `FormElement`
- `InputElement`
- `LinkElement`
- `SelectElement`
- `TextareaElement`

And all these classes must be inherited from `HtmlElement`.

The actual methods and attributes from `DriverAPI` should only be in these classes when it makes sense. We need also other specialized methods and attributes to make the use of these elements easy. For example:
- `FormElement.submit()` -- submits the form
- `FormElement.method` -- returns the `method` attribute of the HTML tag
- `FormElement.action` -- returns the `action` attribute of the HTML tag
- `SelectElement.options` -- returns a list with the options
- etc.

This issue is related to:
- #8: refactor form methods
- #107: Exposes "submit" method on form elements