package test01; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class T1 { public static void main(String[] args) { WebDriver wd =new FirefoxDriver(); //登录 wd.get("https://mail.qq.com/"); wd.switchTo().frame(0); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } wd.findElement(By.id("switcher_plogin")).click(); wd.findElement(By.id("u")).sendKeys("2659980");//账号 wd.findElement(By.id("p")).sendKeys("aa23");//密码 wd.findElement(By.id("login_button")).click(); (new WebDriverWait(wd, 10)).until(ExpectedConditions.presenceOfElementLocated(By.className("toptitle"))); //已进入,开始写信! wd.findElement(By.id("composebtn")).click();//写信 wd.switchTo().frame("mainFrame"); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } //wd.findElement(By.id("toAreaCtrl")).clear(); try { Thread.sleep(500); } catch (InterruptedException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } wd.findElement(By.xpath("//*[@id=\"toAreaCtrl\"]/div[2]/input")).sendKeys("76105@qq.com");//收件人 wd.findElement(By.id("subject")).sendKeys("Selenium测试"); wd.findElement(By.className("qmEditorIfrmEditArea")).click(); wd.findElement(By.className("qmEditorIfrmEditArea")).sendKeys("111111");//内容 wd.findElement(By.name("UploadFile")).sendKeys("/Users/gaoyaxuan/Desktop/11.html");//附件 try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } wd.findElement(By.partialLinkText("发送")).click(); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } wd.close(); } }
难点:1.找到qq收件人的input区域,定位到xpath.
2.正文定位,只有Iframe,直接定位到iframe直接传参.
还没有评论,来说两句吧...