Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dajuntest opened this issue Oct 20, 2019 · 1 comment

Comments

@dajuntest
Copy link

`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')`

@defnngj
Copy link
Collaborator

defnngj commented Oct 24, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants