Python-selenium Page Object Design mode

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.