class SimplePage(Page): el_list = ElementMap(Locators.CLASS_NAME, "element") el_list_wait = ElementMap( Locators.CLASS_NAME, "elements", timeout=1) el_list_only_if = ElementMap( Locators.CLASS_NAME, "elements", timeout=1, only_if=lambda els: len(els) == 1)
class SimplePage(Page): el_map_default = ElementMap(Locators.CLASS_NAME, "simple_class") el_map_keymapper = ElementMap(Locators.CLASS_NAME, "simple_class" , key = lambda el: el.find_element_by_tag_name("a").text) el_map_valuemapper = ElementMap(Locators.CLASS_NAME, "simple_class" , value = lambda el: el.find_element_by_tag_name("a").text) el_map_keyvaluemapper = ElementMap(Locators.CLASS_NAME, "simple_class" , key = lambda el: el.find_element_by_tag_name("a").text , value = lambda el: el.find_element_by_tag_name("a").get_attribute("href"))
class WikiPedia(Page): languages = ElementMap( Locators.CLASS_NAME, "central-featured-lang" , key = lambda el:el.get_attribute("lang") , value = lambda el: el.find_element_by_tag_name("a")) search_box = Element( Locators.CSS_SELECTOR, "input#searchInput" ) article_title = Element( Locators.CSS_SELECTOR, "h1#firstHeading span[dir=auto]" ) search_results = ElementMap( Locators.CSS_SELECTOR, "div.mw-search-result-heading>a") def search(self, query ): self.search_box.clear() self.search_box.send_keys( query ) self.search_box.submit()
class ExhaustivePage(Page): element = Element(Locators.NAME, "e1") element_invalid = Element(Locators.NAME, "3e") elements = Elements(Locators.NAME, "e2") elements_invalid = Elements(Locators.NAME, "3e") elementmap = ElementMap(Locators.NAME, "e3") elementmap_for_ref = ElementMap(Locators.NAME, "e2") elementmap_invalid = ElementMap(Locators.NAME, "3e") elementmap_raw = { "e4": Element(Locators.NAME, "e4"), "e2": Elements(Locators.NAME, "e2"), "e3": ElementMap(Locators.NAME, "e3") } elements_raw = [ Element(Locators.NAME, "e4"), Elements(Locators.NAME, "e2"), ElementMap(Locators.NAME, "e3") ] element_list_raw = [ Element(Locators.NAME, "e4"), Element(Locators.NAME, "e6") ] element_map_raw = { "e4": Element(Locators.NAME, "e4"), "e6": Element(Locators.NAME, "e6") } element_second = Element(Locators.NAME, "e2") element_ref = Element( Locators.NAME, "e6", base_element=elements[0] ) element_map_ref = Element( Locators.NAME, "e6", base_element=elementmap_for_ref["e2 - 1\ne6"] ) element_ref_direct = Element( Locators.NAME, "e6", base_element=element_second ) element_ref_webelement = Element( Locators.NAME, "e6", base_element=web_element ) element_ref_invalid = Element( Locators.NAME, "e6", base_element=42 )
class GoogleMain(Page): search_box = Element( Locators.NAME, "q", timeout = 1) google_buttons = ElementMap ( Locators.CLASS_NAME, "gbts" , timeout = 1 ) search_results = Elements( Locators.CSS_SELECTOR, "li.g>div.rc", timeout = 1, value = lambda el : { "link":el.find_element_by_css_selector("h3.r>a").get_attribute("href"), "title":el.find_element_by_css_selector("h3.r>a").text }) def search ( self, query ): self.google_buttons["Search"].click() # self.google_buttons behaves just like a dictionary self.search_box.clear() # self.search_box is now evaluated directly to a WebElement self.search_box.send_keys(query) self.search_box.submit()
class TestPage(Page): el = Element(Locators.NAME, "el") els = Elements(Locators.NAME, "els") elmap = ElementMap(Locators.NAME, "elmap") sections = TestSections(Locators.NAME, "sections") section = TestSection(Locators.NAME, "section") def do_stuff(self, a, b): return a+b def do_stuff_no_args(self): return True def do_stuff_var_args(self, *args, **kwargs): return args, kwargs
class P(Page): e = Element(Locators.CLASS_NAME, "el") es = Elements(Locators.CLASS_NAME, "el") em = ElementMap(Locators.CLASS_NAME, "el")
class TestSection(Section): el = Element(Locators.NAME, "el") els = Elements(Locators.NAME, "els") elmap = ElementMap(Locators.NAME, "elmap")
class MainPageWithCallable(BasePage): references = ElementMap ( Locators.CLASS_NAME, "reference-link") reference_content = Element(Locators.ID, "reference-content") selenium = Element(Locators.LINK_TEXT, "Selenium", timeout=5)
class P(Page): cl_els = ElementMap(Locators.CLASS_NAME, "cls", timeout=5)
class SimplePage(Page): el_list_only_if = ElementMap( Locators.CLASS_NAME, "elements", filter_by=lambda el: el.text != "element_text")