.. _filtering:
Filtering
=========
The ``filter()`` and ``exclude()`` methods can be used to select a subset of
elements from a ``WebElementSet``.
filter(*selector*)
------------------
Filters a ``WebElementSet`` to only include elements that match the selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
...
... - 1
... - 2
... - 3
... - 4
... - 5
...
"""
>>> WebDriver().open(snippet).find('li').filter('.selected')
WebElementSet(
2
5
)
exclude(*selector*)
-------------------
Filters a ``WebElementSet`` to only include elements that do not match the
selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
...
... - 1
... - 2
... - 3
... - 4
... - 5
...
"""
>>> WebDriver().open(snippet).find('li').exclude('.selected')
WebElementSet(
1
3
4
)