如何使用Java在Selenium2(Webdriver)中输入Gmail正文文本 [英] How to type Gmail Body text in Selenium2 (Webdriver) using Java

查看:127
本文介绍了如何使用Java在Selenium2(Webdriver)中输入Gmail正文文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图自动从Gmail发送电子邮件(https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=http://mail.google.com/mail/ & scc = 1& ltmpl = default& ltmplcache = 2)通过使用Selenium WebDriver和Java。首先,我尝试使用Selenium IDE记录测试。 IDE无法记录电子邮件的正文。
我尝试通过以下方式输入正文文本,但不幸的是它失败了。



driver.findElement(Byxpath(// textarea [名称='body']))。sendKeys(body text);

错误是:FAILED:testSendingEmail
org.openqa.selenium.ElementNotVisibleException :元素当前不可见,所以不能与命令持续时间或超时进行交互:30.02秒

任何人都可以请我帮忙吗?

解决方案

以下是用于输入gmail正文的HTML代码片段:

 < iframe frameborder =0style =padding:0pt; height:218px; background-color:white; class =Am Al editableid =:4ztabindex =1>< / iframe> 

我在WebDriver中编写了下面的java代码来输入gmail正文,并且它工作得很好。 (我很高兴)

  WebDriver driver = new FirefoxDriver(); 
WebElement frame1 = driver.findElement(By.xpath(// iframe [@ class ='Am Al editable']));
driver.switchTo().frame(frame1);
WebElement editable = driver.switchTo()。activeElement();
String mailBody =+'\\\
'+我是来自孟加拉国达卡的Ripon。;
editable.sendKeys(mailBody);
driver.switchTo()。defaultContent();


I tried to automate sending email from Gmail (https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=http://mail.google.com/mail/&scc=1&ltmpl=default&ltmplcache=2) by using Selenium WebDriver with Java. First I tried to record the test by using Selenium IDE. IDE failed to record the body of email. I tried by the following way to type on body text, but it failed unfortunately.

driver.findElement(By.xpath("//textarea[@name='body']")).sendKeys("body text");

Error is: FAILED: testSendingEmail org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 30.02 seconds

Can anybody please help me?

解决方案

The following is the piece of HTML code for typing gmail body:

<iframe frameborder="0" style="padding: 0pt; height: 218px; background-color: white;" class="Am Al editable" id=":4z" tabindex="1"></iframe>

I have written the following java code in WebDriver to type gmail body and it worked nicely. (I am happy)

WebDriver driver = new FirefoxDriver();
WebElement frame1 = driver.findElement(By.xpath("//iframe[@class='Am Al editable']"));
driver.switchTo().frame(frame1);
WebElement editable = driver.switchTo().activeElement();
String mailBody = "Hi," + '\n' + "I'm Ripon from Dhaka, Bangladesh.";
editable.sendKeys(mailBody);
driver.switchTo().defaultContent();

这篇关于如何使用Java在Selenium2(Webdriver)中输入Gmail正文文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆