cobrateam / cobrateam/splinter

Return tag-specific objects in DriverAPI.find_* methods

Open
#111 2 comments 0 reactions 0 assignees View on GitHub
brainstorm
Dominant language
Python
Stars
2.7k
Forks
511
PR merge metrics
No merged PRs in 30d

Description

`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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.