[Selenium] When the DOM structure inside the iframe,iframe inside is HTML, how to send the keys to the body inside, how to use Assert to verify?

Source: Internet
Author: User

I encountered a problem during the test, and I was unable to find the HTML underneath the IFRAME through Cssselector:

<div id= "Maileditordiv" style= "Display:inline-block;" ><div class= "Maileditor" ><div style= "height:130px;" ><div class= "Divbody" ><div class= "Ke-container ke-container-default" style= "width:620px;" ><div class= "Ke-toolbar" style= "Display:block;" unselectable= "on" ><div class= "Ke-edit" style= "Display: Block height:286px; " ><iframe class= "ke-edit-iframe" frameborder= "0" hidefocus= "true" style= "width:100%; height:286px; " ><HTML>body class= "ke-content" >rrrrrrrt</body>< /html>

Later I found that I could only find the IFRAME here, and then I could not find it. I have used SendKeys to can send text to body, but want to verify the text of the IFRAME through assert, unable to do.

Workaround:

The problem is solved by switching the driver to the IFRAME and then switching back.

public void Sendkeystomailbodyeditboxandcheck (String mailbody) {webelement el = Page.getmailbodyeditbox (); El.sendkeys (Mailbody); Driver.switchto (). FRAME (EL); Assert.assertequals (Driver.findelement (By.xpath ("//html/body")). GetText (), Mailbody, "'" +mailbody+ "' should be displayed in mail body. "); Driver.switchto (). Defaultcontent ();}

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.