After you log in to Cnblog with Python+selenium, add the article and then delete the article again and verify

Source: Internet
Author: User

Purpose: After you log in to Cnblog, add the article and then delete the article again and verify

The code is as follows:

#coding:  utf-8from selenium import webdriverfrom time import sleepimport  unittestimport timeclass deletepost (unittest. TestCase):     def setup (self):         self.dr  = webdriver. Chrome ()         self.dr.maximize_window ()     # Define Login Method     def login (Self, username, password):         self.dr.get (' Https://passport.cnblogs.com/user/signin ')    #cnblog登录页面          self.dr.find_element_by_id (' input1 '). Send_keys (username)          self.dr.find_element_by_id (' Input2 '). Send_keys (password)          self.dr.find_element_by_id (' signin '). Click ()      #定义新增文章方法     def create_post (SELF,&NBsp;title, content):         self.dr.get (' https://i.cnblogs.com/ Editposts.aspx?opt=1 ')    #cnblog新增文章页面         self.dr.find_ element_by_id (' Editor_edit_txbtitle '). Send_keys (title)         self.set _content (content)         self.dr.find_element_by_id (' Editor_Edit_ Lkbpost '). Click ()      #定义输入富文本content方法     def set_content (self,  content):        js =  ' Document.getElementById ("editor _edit_editorbody_ifr "). Contentwindow.document.body.innerhtml=\ '%s\ '  %  (content)          self.dr.execute_script (JS)      #定义获取文章post-id methods      def create_post_and_return_its_id (self, title, content):         self.Create_post (title, content)    #调用新增文章方法, prepare for the post-id of the post that was added later in the article          tokens = self.dr.find_element_by_css_selector (' #TipsPanel_LinkEdit '). Get_attribute (' href '). Split (' = ')         return tokens[-1]  # All articles correspond to unique post-id     #验证删除新增的文章     def test_delete_post_success ( Self):         ' Verify the deletion of the newly added post '          self.login (' kemi_xxxx ',  ' kemi_xxxx ')   #cnblog帐号密码          title =  ' title %s '  % (Time.time ())    #标题为title加当前时间          content =  ' content %s '  % (Time.time ())   # Content Add current time         sleep (5)          post_id = self.create_POST_AND_RETURN_ITS_ID (title, content)   #调用post-id method and get corresponding id         self.dr.get (' https://i.cnblogs.com/')    #cnblog后台管理页面          row_id =  ' post-row-'  + post_id   #定义文章列表的行id          post = self.dr.find_element_by_id (row_id)    #定位到相应行id上          post.find_element_by_xpath ("//a[@href = ' javascript:void (0) ']"). Click ()     #定位删除并点击         self.dr.switch_to_alert (). Accept ()   # Click OK in the pop-up window         sleep (2)          post.find_element_by_xpath ("//span[@style = ' color:red ']")    #定位相应post的 "Delete succeeded! "Prompt (used to verify deletion)     def teardown (self):         Print (' Test finished! ')      &Nbsp;  self.dr.quit () if __name__ ==  ' __main__ ':     unittest.main ( )

The effect is as follows:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/942023/201612/942023-20161227100419414-2039047342. PNG "style=" border:0px; "/>


This article comes from "No idea, no achievement!" "Blog, be sure to keep this provenance http://kemixing.blog.51cto.com/10774787/1886412

After you log in to Cnblog with Python+selenium, add the article and then delete the article again and verify

Related Article

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.