发布时间:2019-08-29 07:41:00编辑:auto阅读(1287)
Page Object是一种程序设计模式,将面向过程转变为面向对象(页面对象),将测试对象及单个的测试步骤封装在每个Page对象中,以page为单位进行管理。可以使代码复用,降低维护成本,提高程序可读性和编写效率。
#用page object思想实现百度首页的搜索和登陆功能 from selenium import webdriver from selenium.webdriver.common.keys import Keys import time class BaiduPage(): url='http://www.baidu.com/' username='XXXXXX' password='******' def __init__(self,driver): self.driver=driver def search(self,kw='51cto'): self.driver.get(self.url) time.sleep(2) self.driver.find_element_by_id('kw').send_keys(kw) self.driver.find_element_by_id('su').click() time.sleep(2) def login(self,username=None,password=None): if username==None: username=self.username if password==None: password=self.password self.driver.get(self.url) time.sleep(2) self.driver.find_element_by_link_text('登录'.decode('utf-8')).click() time.sleep(2) self.driver.find_element_by_id('TANGRAM__PSP_8__userName').send_keys(self.username) self.driver.find_element_by_id('TANGRAM__PSP_8__password').send_keys(self.password) self.driver.find_element_by_id('TANGRAM__PSP_8__submit').click() time.sleep(2) def __del__(self): pass #self.driver.quit() driver=webdriver.Chrome() page=BaiduPage(driver) page.login() self.driver.quit()
上一篇: python 获取6大币对 区块高度
下一篇: 比较全的python cmd模块的用法
47628
46031
36930
34501
29110
25758
24593
19734
19280
17774
5588°
6177°
5717°
5770°
6723°
5504°
5510°
6010°
5982°
7312°