mirror of
https://git.zavage.net/Zavage-Software/wabot.git
synced 2026-07-21 13:06:08 -06:00
48 lines
1.8 KiB
ReStructuredText
48 lines
1.8 KiB
ReStructuredText
Page objects
|
|
============
|
|
|
|
Model each website page as a :class:`wabot.Page` subclass with a
|
|
class-level ``elements`` map; drive them through one
|
|
:class:`wabot.Browser`.
|
|
|
|
.. code-block:: python
|
|
|
|
class Inventory(wabot.Page):
|
|
elements = {
|
|
"search": ("el", ("id", "search-box")),
|
|
"region": ("select", ("id", "region")),
|
|
"instock": ("checkbox", ("id", "in-stock-only")),
|
|
"rows": ("els", ("css selector", "table#items tr")),
|
|
}
|
|
|
|
Element types
|
|
-------------
|
|
|
|
============ ======================================= =====================
|
|
Type key Returned wrapper Main methods
|
|
============ ======================================= =====================
|
|
``el`` :class:`wabot.TextField` get_value / set_value
|
|
``select`` :class:`wabot.SelectField` set_value(value|text)
|
|
``checkbox`` :class:`wabot.CheckField` get/set_checked
|
|
``els`` list of raw WebElements (selenium API)
|
|
a class your :class:`wabot.PageObject` subclass whatever you define
|
|
============ ======================================= =====================
|
|
|
|
Missing elements come back as a falsy :class:`wabot.NullField`, so guard
|
|
with ``if el:`` instead of try/except.
|
|
|
|
Inheritance
|
|
-----------
|
|
|
|
Element lookup walks the MRO: subclasses inherit the parent map and can
|
|
override individual keys — useful for sites with shared page chrome.
|
|
|
|
Verification and delegation
|
|
---------------------------
|
|
|
|
``Browser.set_page(PageClass)`` refuses the switch if the page's
|
|
``verify()`` returns False. Once set, unknown attributes on the Browser
|
|
delegate to the current page: ``bot.log_in(...)`` calls
|
|
``bot.page.log_in(...)``. After any trapped failure the Browser refuses
|
|
further actions until ``bot.reset()``.
|