Splinter learning-simulate a notebook to write a blog, and splinter to write

Source: Internet
Author: User

Splinter learning-simulate a notebook to write a blog, and splinter to write

To verify the various actions of Splinter, we will use Splinter to simulate the additional operations in the blog garden.

Step 1: log on to the blog Park and learn the same method as Splinter-Preliminary Study 2. Simulate the login of the blog Park

Step 2: Go to the "add essay" Page and click "my blog"> "New essay".

Here, we use the find_link_by_text (text) method to find the corresponding link and then click, as shown in:

Browser. find_link_by_text ("My blog"). first. click ()

It is equivalent to browser. click_link_by_text ("My blog ")

Step 3: Enter the title/Content

Obtain the page elements corresponding to the content to be filled in or selected through the review element and perform the operations respectively.

1) Title

Find the ID of the corresponding element as Editor_Edit_txbTitle, and fill in it using the fill () method.

2) Content

The content area corresponds to an iframe with the ID Editor_Edit_EditorBody_ifr. The embedded html document in the iframe contains only the head and body, and the body is dynamically filled with the input content, for example:

  

Here, you can use the execute_script () method of the Browser object to fill in the body content section, as follows:

 

  iframe.execute_script('document.getElementById("tinymce").innerHTML = "<p>Hello world!</p><p>First Splinter test!</p>"')

 

Note that the body to ID is tinymce.

  

3) select items in website category

The items selected in the website category are single options. You can locate the corresponding options directly, and then select the check () method. Note that you must click "website category" first ", otherwise, the elements are invisible.

# Select python as the programming language
Browser. find_by_id ("Editor_Edit_APOptions_APSiteCategory_Link"). click () # Open website category
Time. sleep (1)
Browser. find_by_id ("site_categroy_108696"). first. check () # click python
Browser. find_by_id ("site_categroy_108737"). first. check () # click html5. overwrite the previous selection.

The final result is subject to the last selection.

4) Select "not displayed on the homepage" and "no comments allowed"

By default, the blog is "commented upon". Here, the comment is removed, and no comment is allowed. The uncheck () method can be used to cancel selected items.

# Do not display on the home page, do not allow comments
Browser. find_by_id ("Editor_Edit_Advanced_chkDisplayHomePage"). first. uncheck ()
Browser. find_by_id ("Editor_Edit_Advanced_chkComments"). first. uncheck ()

5) Save as draft

The Code is as follows:

  

1 def get_publish_page (self): 2 "3 jump to" add essay "Page 4: return: 5" 6 if self. browser is None: 7 return 8 else: 9 # self. browser. find_by_id ("header_user_right "). first. find_by_xpath ("a") 10 self. browser. click_link_by_text ("My blog") 11 # <=> self. browser. find_link_by_text ("My blog "). first. click () 12 time. sleep (3) 13 self. browser. find_link_by_text ("New essay "). first. click () 14 15 def write_blog (self): 16 "17 write a blog 18: return: 19 "20 # title 21 self. browser. find_by_id ("Editor_Edit_txbTitle "). first. fill ("Splinter Study") 22 23 # content 24 with self. browser. get_iframe ("Editor_Edit_EditorBody_ifr") as iframe: 25 # iframe. find_by_xpath ("browserody "). first. fill ("Writing success? ") 26 iframe.exe cute_script ('document. getElementById (" tinymce "). innerHTML =" <p> Hello world! </P> <p> First Splinter test! </P> "') 27 28 # select python29 self as the programming language. browser. find_by_id ("Editor_Edit_APOptions_APSiteCategory_Link "). click () 30 time. sleep (1) 31 self. browser. find_by_id ("site_categroy_108696 "). first. check () 32 self. browser. find_by_id ("site_categroy_108737 "). first. check () 33 34 # not displayed on the home page, comment 35 self. browser. find_by_id ("Editor_Edit_Advanced_chkDisplayHomePage "). first. uncheck () 36 self. browser. find_by_id ("Editor_Edit_Advanced_chkComments "). first. uncheck () 37 38 # Save as draft 39 self. browser. find_by_id ("Editor_Edit_lkbDraft "). first. click ()Add a notebook in the blog garden Simulation

 

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.