.. _traversing:
Traversing
==========
WebDriver Plus supports a large set of JQuery style DOM traversal methods.
These help you to you easily target the parts of the web page you're interested
in.
Traversal methods in WebDriver Plus can be called without any arguments:
.. code-block:: python
>>> elems.children()
Or they can be filtered by one or more selectors:
.. code-block:: python
>>> elems.children('input', type='checkbox')
children(*selector*)
--------------------
Get the children of each element in the set of matched elements, optionally
filtered by a selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
...
"""
>>> WebDriver().open(snippet).find('ul').children()
WebElementSet(
1
2
3
)
parent(*selector*)
------------------
Get the parent of each element in the current set of matched elements,
optionally filtered by a selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
... """
>>> WebDriver().open(snippet).find('strong').parent()
WebElementSet(
2
)
descendants()
-------------
Get the descendants of each element in the current set of matched elements.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
... """
>>> WebDriver().open(snippet).find('ul').descendants()
WebElementSet(
1
2
2
3
)
.. note::
Unlike the other traversal operations ``.descendants()`` cannot be
filtered by a selector. You should use ``.find()`` instead, which is
equivelent to filtering against all descendants.
ancestors(*selector*)
---------------------
Get the ancestors of each element in the current set of matched elements,
optionally filtered by a selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
... """
>>> WebDriver().open(snippet).find('.selected').parents()
WebElementSet(
)
next(*selector*)
----------------
Get the immediately following sibling of each element in the set of matched
elements, optionally filtered by a selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
...
... - 1
... - 2
... - 3
... - 4
... - 5
...
"""
>>> WebDriver().open(snippet).find('li.selected').next()
WebElementSet(
4
)
prev(*selector*)
----------------
Get the immediately preceding sibling of each element in the set of matched
elements, optionally filtered by a selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
...
... - 1
... - 2
... - 3
... - 4
... - 5
...
"""
>>> WebDriver().open(snippet).find('li.selected').prev()
WebElementSet(
2
)
next_all(*selector*)
--------------------
Get all following siblings of each element in the set of matched elements,
optionally filtered by a selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
...
... - 1
... - 2
... - 3
... - 4
... - 5
...
"""
>>> WebDriver().open(snippet).find('li.selected').next_all()
WebElementSet(
4
5
)
prev_all(*selector*)
--------------------
Get all preceding siblings of each element in the set of matched elements,
optionally filtered by a selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
...
... - 1
... - 2
... - 3
... - 4
... - 5
...
"""
>>> WebDriver().open(snippet).find('li.selected').prev_all()
WebElementSet(
1
2
)
siblings(*selector*)
--------------------
Get the siblings of each element in the set of matched elements, optionally
filtered by a selector.
.. code-block:: python
>>> from webdriverplus import WebDriver
>>> snippet = """
...
... - 1
... - 2
... - 3
... - 4
... - 5
...
"""
>>> WebDriver().open(snippet).find('li.selected').siblings()
WebElementSet(
1
2
4
5
)