Python webdriver api-operation Rich Text box-to be continued

Source: Internet
Author: User
Tags xpath

Operation Rich Text box-is the message body part, can choose the font what the first way: generally in the IFRAME, to cut in, is generally "html/body", after editing, then cut out, and then Send_keys on the end of the child

#encoding =utf-8

From selenium import Webdriver

Import UnitTest, Time, Traceback

From Selenium.webdriver.support.ui import webdriverwait

From Selenium.webdriver.support import expected_conditions as EC

From selenium.common.exceptions import TimeoutException, nosuchelementexception

From selenium.webdriver.common.by Import by

Class Testdemo (UnitTest. TestCase):

def setUp (self):

# launch Firefox browser

#self. Driver = Webdriver. Ie (Executable_path = "E:\\iedriverserver")

Self.driver = Webdriver. Firefox (executable_path= "C:\\geckodriver")

def test_sohumailsendemail (self):

url = "Http://mail.sohu.com"

# Visit Sohu Email Login page

Self.driver.get (URL)

Try

UserName = self.driver.find_element_by_xpath\

(U '//input[@placeholder = "Please enter your email"]

Username.clear ()

Username.send_keys ("Fosterwu")

PassWord = self.driver.find_element_by_xpath\

(U '//input[@placeholder = "Please enter your password"]

Password.clear ()

Password.send_keys ("1111")

Login = Self.driver.find_element_by_xpath (U '//input[@value = "Login"]

Login.click ()

wait = webdriverwait (Self.driver, 10)

# show Wait, determine if the page is successfully logged in and jump to the home after successful login

Wait.until (ec.element_to_be_clickable\

((By.xpath, '//li[text () = "Write Mail"]))

Self.driver.find_element_by_xpath (U '//li[text () = "Write Mail"]). Click ()

Time.sleep (2)

Receiver = self.driver.find_element_by_xpath\

('//div[@arr = ' mail.to_render ']//input ')

# Enter Recipient

Receiver.send_keys ("[email protected]")

Subject = Self.driver.find_element_by_xpath\

('//input[@ng-model= "Mail.subject"])

# Enter message header

Subject.send_keys (U "a Test e-mail!) ")

# get an IFRAME page element object in the message body editing area

iframe = self.driver.find_element_by_xpath\

('//iframe[contains (@id, "Ueditor")]

# switch into rich text box with Switch_to.frame () method

Self.driver.switch_to.frame (IFRAME)

# Get Rich text box in edit page element object

EditBox = Self.driver.find_element_by_xpath ("/html/body")

# Enter Message body

Editbox.send_keys (U "message body content")

# switch out of the rich text box and go back to the default page

Self.driver.switch_to.default_content ()

# Find the "Send" button on the page and click on it

Self.driver.find_element_by_xpath ('//span[.= ' sent "]"). Click ()

# Display is waiting for page elements containing the keyword "send success" to appear on the page

Wait.until (ec.visibility_of_element_located\

((By.xpath, '//span[.= "send Success"]))

Print u "Mail sent successfully"

Except TimeoutException:

Print U "show wait page element timed out"

Except nosuchelementexception:

Print U "Looking for page element does not exist", Traceback.print_exc ()

Except Exception:

# Print additional exception stack information

Print Traceback.print_exc ()

def tearDown (self):

# Quit IE browser

Self.driver.quit ()

if __name__ = = ' __main__ ':

Unittest.main ()

D:\test>python test.py

Message sent successfully

.

----------------------------------------------------------------------

Ran 1 Test in 58.226s

Ok

Python webdriver api-operation Rich Text box-to be continued

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.