selenium测试126邮箱新增联系人

上一篇 / 下一篇  2016-09-14 16:25:36 / 个人分类:selenium

 看的书里面有个测试126邮箱新增联系人的功能,用书中的代码已经完全无法定位了,所以就自己去写了代码测试了一下,搞了一下午才搞出来。
登陆的时候他的登陆信息都是放在一个iframe里面的,必须切换到这个frame才能进行操作;
新增联系人页面的定位还是有点困难。
 
package dhb.appModules;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test;
public class NewTest {
  @Test
  public void f() {
   WebDriver driver=new InternetExplorerDriver();
   driver.get("http://mail.126.com/");
   WebElement ifr=driver.findElement(By.tagName("iframe"));
   driver.switchTo().frame(ifr);
   WebElement name=driver.findElement(By.xpath("//input[@name='email']"));
   name.clear();
   name.sendKeys("**********你的账号名称*********");
   WebElement pswd=driver.findElement(By.name("password"));
   pswd.clear();
   pswd.sendKeys("*****你申请账号的密码*********");
   System.out.println(driver.getWindowHandle().toString());
  
  WebElement button=driver.findElement(By.id("dologin"));
  button.click();

  driver.switchTo().defaultContent();
  System.out.println(driver.getTitle());
  WebDriverWait wait=new WebDriverWait(driver, 30);
  wait.until(ExpectedConditions.textToBePresentInElement(By.id("spnUid"), "*****你申请的账号+@126.com*****"));
   
 System.out.println(driver.getTitle());
 Assert.assertTrue(driver.getPageSource().contains("未读邮件"));
 driver.findElement(By.xpath("//div[@id='dvMultiTab']/ul/li[2]/div[3]")).click();
 WebElement pp=driver.findElement(By.xpath("//div[@id='dvContainer']/div/header/div/div[1]/div/span[2]"));
 System.out.println(pp.getAttribute("class"));
 pp.click();
 try {
  Thread.sleep(2000);
 } catch (InterruptedException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 WebElement username=driver.findElement(By.xpath("//div[@id='contact_edit_main_normal']/dl[1]/dd/div/input"));
 WebElement email=driver.findElement(By.xpath("//div[@id='iaddress_MAIL_wrap']/dl/dd/div/input"));
 WebElement telno=driver.findElement(By.xpath("//div[@id='iaddress_TEL_wrap']/dl/dd/div/input"));
 WebElement beizhu=driver.findElement(By.xpath("//div[@id='contact_edit_main_normal']/dl[3]/dd/div/textarea"));
 WebElement submit=driver.findElement(By.xpath("//div[starts-with(@id,'_mail_msgbox_')]/div[3]/div[2]/div[1]/span"));
 username.sendKeys("棉花糖");
 email.sendKeys("棉花糖@qq.com");
 telno.sendKeys("13555555555");
 beizhu.sendKeys("这是牛逼人物");
 submit.click();
  }
}


TAG: 126邮箱 联系人

 

评分:0

我来说两句

日历

« 2024-04-29  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 7969
  • 日志数: 7
  • 建立时间: 2016-09-11
  • 更新时间: 2017-06-18

RSS订阅

Open Toolbar