如何切换到框架以在Gmail的邮件正文中编写文本?

时间:2018-12-07 10:27:29

标签: selenium-webdriver iframe automation gmail frames

我有一种在Gmail中撰写邮件的方法,我正面临着切换框架以在邮件正文中书写的问题。

  • 什么时候可以说代码中需要更改框架?
  • 在这种情况下如何识别框架?

    public Mail composeMail(){
    
    WebDriverWait wait = new WebDriverWait(driver, 60);
    wait.until(ExpectedConditions.elementToBeClickable(compose));
    
    compose.click();
    fullScreen.click();
    recipients.sendKeys("paliwal.sumit31@gmail.com");
    subject.sendKeys("Gmail_Automation - Demo Mail");
    
    driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='__HC_94253229']")));
    driver.switchTo().activeElement().sendKeys("test message");
    }
    

    HTML代码:

<iframe ng-non-bindable="" frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" style="border: none; margin-bottom: -4px; width: 340px; height: 128px;" tabindex="-1" vspace="0" width="100%" id="" name="__HC_94253229" src="https://contacts.google.com/widget/hovercard/v/2?authuser=0&amp;origin=https%3A%2F%2Fmail.google.com&amp;usegapi=1&amp;jsh=m%3B%2F_%2Fscs%2Fabc-static%2F_%2Fjs%2Fk%3Dgapi.gapi.en.CUp85wbT4DI.O%2Frt%3Dj%2Fd%3D1%2Frs%3DAHpOoo-XBQda2DFvo9hxbj_dGnCV84SJMA%2Fm%3D__features__#id=__HC_94253229&amp;_gfid=__HC_94253229&amp;parent=https%3A%2F%2Fmail.google.com&amp;pfname=&amp;rpctoken=29482633"></iframe>

.
.
.
.
.



<div id=":o3" class="Ar Au" style="display: block;"><div id=":116" class="Am Al editable LW-avf" hidefocus="true" aria-label="Message Body" g_editable="true" role="textbox" aria-multiline="true" contenteditable="true" tabindex="1" style="direction: ltr; min-height: 80px;"><br></div></div>

请仔细检查在浏览器中检查“撰写邮件HTML”代码。

0 个答案:

没有答案