Logical ContainersΒΆ

Logical containers are classes that represent some part of user interface but there is no need to search for them. Only child elements are found but they are found uniquely without nested searches (e.g. by id).

For example some menu should be placed on some of your pages but menu items have ids and you don’t need to narrow search by ordinary container. In such case search will be performed globally on the page but elements are stored within Menu class.

The difference between logical and ordinary containers:

  • inheritance from WebElement, logical containers are not inherited from it
  • when declaring a logical container in a Page Object class arguments for by and value parameters are not passed in Find call
from selenium.webdriver.common.by import By
from webium import Find, BasePage


class Header(object):
    sign_in = Find(by=By.CSS_SELECTOR, value='a[href*="auth/oid/new"]')
    register = Find(by=By.CSS_SELECTOR, value='a[href*="registration"]')


class StructuredPage(BasePage):
    # here we are just grouping Header elements together without any influence on actual search
    header = Find(Header)

    def __init__(self):
        super(StructuredPage, self).__init__(url='http://wargaming.net')


if __name__ == '__main__':
    page = StructuredPage()
    page.open()
    print(page.header.sign_in.text)
    print(page.header.register.text)