Selenium2+python Automation 23-Rich Text (auto Post)

Source: Internet
Author: User

Objective

Rich text editing box is to do the most common web automation scene, a lot of small partners encountered do not know how to do, this article with the blog Garden Editor For example, to solve how to locate rich text, input text content

First, load the configuration

1. Open the blog Park to write essays, first need to login, here in order to avoid revealing personal account information, I directly loaded the configuration file, free login.

Do not know how to load the configuration file, see this article Selenium2+python Automation 18-load Firefox configuration

Second, open the editing interface

1. Blog Home address: Bolgurl = "http://www.cnblogs.com/"

2. My Blog Park address: Yoyobolg = bolgurl + "Yoyoketang"

3. Click the "New essay" button, Id=blog_nav_newpost

Third, IFRAME switch

1. After opening the editing interface, do not rush to enter the content, first sleep for a few seconds

2. Enter the title, here directly through the ID can be located, no difficulty

3. Next is the focus of the rich text editor, where the edit box has an IFRAME, so you need to first switch

(The IFRAME does not understand that can be seen in the previous article: Selenium2+python automation 14-iframe)

Iv. Input Body

1. Here the edit body is positioned in the red box where the body part, i.e. ID=TINYMCE

2. After locating, the direct Send_keys () method can be used to enter the content.

3. Some of the small partners may not be successful input, can be entered before the first table key, Send_keys (Keys.tab)

Five, reference code:

# Coding:utf-8
From selenium import Webdriver
From Selenium.webdriver.common.keys import keys
Import time

Profiledir = R ' C:\Users\Gloria\AppData\Roaming\Mozilla\Firefox\Profiles\1x41j9of.default '
Profile = Webdriver. Firefoxprofile (Profiledir)
Driver = Webdriver. Firefox (Profile)

Bolgurl = "http://www.cnblogs.com/"
Yoyobolg = Bolgurl + "Yoyoketang"
Driver.get (YOYOBOLG)
driver.find_element_by_id ("Blog_nav_newpost"). Click ()

Time.sleep (5)
Edittile = u "Selenium2+python Automation 23-Rich Text"
Editbody = u "Here is the text of the post"
driver.find_element_by_id ("Editor_edit_txbtitle"). Send_keys (Edittile)
Driver.switch_to.frame ("Editor_edit_editorbody_ifr")
driver.find_element_by_id ("TinyMCE"). Send_keys (Keys.tab)
driver.find_element_by_id ("TinyMCE"). Send_keys (Editbody)

Selenium2+python Automation 23-Rich Text (auto Post)

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.