Selenium2+python automated 24-js Processing Rich text (with IFRAME) "reprint"

Source: Internet
Author: User

Objective

Previous Selenium2+python Automation 23-Rich Text (auto post) solve the rich text iframe problem, in fact, nothing special, mainly the switch of the IFRAME, this article explains through the JS method to deal with the problem of IFrame on Rich text

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, locate the IFRAME

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)

Four, JS input Chinese

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

2. After positioning, use the JS method to input directly without switching the IFRAME

3. Direct Point Save button, no need to cut back

Five, reference code:

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

# Profiledir path corresponding to direct PC configuration path
Profiledir = R ' C:\xxx\xxx\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)


BODY = "Here is the text content of the message via JS"

# JS processing iframe problem (JS code is too long, I split into two lines)
JS = ' document.getElementById ("Editor_edit_editorbody_ifr") ' \
'. Contentwindow.document.body.innerhtml= '%s '% body
Driver.execute_script (JS)
# Save Drafts
driver.find_element_by_id ("Editor_edit_lkbdraft"). Click ()

Selenium2+python automated 24-js Processing Rich text (with IFRAME) "reprint"

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.