|
发到自己博客直接被扔进垃圾箱,这网站的博客是没法玩了,那就发帖也要玩!!
看的书里面有个测试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("dhbautotest");
WebElement pswd=driver.findElement(By.name("password"));
pswd.clear();
pswd.sendKeys("duanhong");
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"), "dhbautotest@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();
}
}
|
|