Find¶
webium.find.Find
finds a single element within page or other container.
By default found element class is WebElement
.
Main two parameters for Find are:
by
- what search strategy to usevalue
- what value should be used to find an element
from selenium.webdriver.common.by import By
from webium import BasePage, Find
class SomePage(BasePage):
join_link = Find(by=By.CSS_SELECTOR, value='a[href*="registration"]')
def __init__(self):
super(SomePage, self).__init__(url='http://wargaming.net')
if __name__ == '__main__':
page = SomePage()
page.open()
page.join_link.click()
ui_type¶
If you want to specify your own classes for controls ui_type
is the parameter for Find
to use your class.
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from webium import BasePage, Find
class Link(WebElement):
def is_secure(self):
return self.get_attribute('href').startswith('https://')
class TypedPage(BasePage):
join_link = Find(Link, By.CSS_SELECTOR, 'a[href*="registration"]')
def __init__(self):
super(TypedPage, self).__init__(url='http://wargaming.net')
if __name__ == '__main__':
page = TypedPage()
page.open()
print('Is link secure: ' + str(page.join_link.is_secure()))
context¶
There are cases when you can’t specify page structure before actual run. Modern pages are dynamic and fuzzy. If you can’t specify Find as class attribute you should directly provide page object instance to perform search.
from selenium.webdriver.common.by import By
from webium import BasePage, Find
class DynamicPage(BasePage):
def __init__(self):
super(DynamicPage, self).__init__(url='http://wargaming.net')
def get_link_by_href(self, href):
return Find(by=By.CSS_SELECTOR, value='a[href*="{0}"]'.format(href), context=self)
if __name__ == '__main__':
page = DynamicPage()
page.open()
page.get_link_by_href('registration').click()