poium icon indicating copy to clipboard operation
poium copied to clipboard

用生产者模式对页面操作再做了个封装 可以让代码更简洁点

Open dajuntest opened this issue 6 years ago • 1 comments

`from poium import Page, PageElement from selenium import webdriver

class BaiduIndexPage(Page):

search_input = PageElement(css="#kw", describe="搜索框")
search_button = PageElement(css="#su", describe="搜索按钮")

class CPCLoginPage(Page): login = PageElement(id_='id', describe='登录') pass

class ToutolPage(BaiduIndexPage, CPCLoginPage): pass

class WebAction(object):

page = ToutolPage(webdriver.Chrome())

# 动态传入类属性
@classmethod
def with_click(cls, click_element):
    if hasattr(cls.page, click_element):
        getattr(cls.page, click_element).click()
    return cls

@classmethod
def with_input(cls):
    cls.page.search_input.send_keys('poium')
    return cls

@classmethod
def with_open(cls):
    cls.page.get('https://www.baidu.com')
    return cls

if name == 'main': weba = WebAction() weba.with_open().with_input().with_click('search_button')`

dajuntest avatar Oct 20 '19 16:10 dajuntest

感谢你提供的范例,请使用markdown 编写你的代码,这样更容易被别人看懂!😸

defnngj avatar Oct 24 '19 10:10 defnngj