FindsΒΆ

Another way to handle dynamic pages where the number of elements is not defined is Finds class. It works the same way as Find with the same parameters but returns list of elements.

from selenium.webdriver.common.by import By
from webium import BasePage, Finds


class LinksPage(BasePage):
    links = Finds(by=By.TAG_NAME, value='a')

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


if __name__ == '__main__':
    page = LinksPage()
    page.open()
    print('Number of links: ' + str(len(page.links)))

And you can even have a dynamic list of typed elements.

from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from webium import BasePage, Finds


class Link(WebElement):
    def is_secure(self):
        return self.get_attribute('href').startswith('https://')


class TypedPage(BasePage):
    links = Finds(Link, By.TAG_NAME, 'a')

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

    def get_unsecured_links(self):
        return filter(lambda link: not link.is_secure(), self.links)


if __name__ == '__main__':
    page = TypedPage()
    page.open()
    print('Number of unsecured links: ' + str(len(page.get_unsecured_links())))