Page object is a programming pattern that transforms a process into an object-oriented (Page object), encapsulates a test object and a single test step in each Page object, and manages it in page. You can reuse code, reduce maintenance costs, and improve program readability and authoring efficiency.
#用page object thought to realize the search and landing function of Baidu homepage from selenium import webdriverfrom Selenium.webdriver.common.keys import keysimport timeclass 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) &nbsP; 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 (' Login '. 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 ()
This article from "Today's efforts, tomorrow's success!" "Blog, be sure to keep this provenance http://zhzhgo.blog.51cto.com/10497096/1692057
Python-selenium Page Object Design mode