selenium webdriver登录163邮箱发送邮件的实例

上一篇 / 下一篇  2012-12-21 10:24:11 / 个人分类:Selenium

package com.test;
*u d ` [U\i:o051Testing软件测试网/YyLA oy
import java.util.List;
5O1f6s*{3c:ke3c051Testing软件测试网'Fc%H k:t2`i
import org.openqa.selenium.By;51Testing软件测试网JMR:EJ4p-p(fsq
import org.openqa.selenium.WebDriver;51Testing软件测试网HGj-l'kk ]
import org.openqa.selenium.WebElement;51Testing软件测试网%zeK%v&l^Z
import org.openqa.selenium.chrome.ChromeDriver;51Testing软件测试网e b;sm,M6Rj
import org.openqa.selenium.firefox.FirefoxDriver;51Testing软件测试网5^2E I\5Y+\ Fls
import org.openqa.selenium.ie.InternetExplorerDriver;51Testing软件测试网 S@ M N8Ja1dA
import org.openqa.selenium.interactions.Actions;
P)XW1_.E-}&NC,X M0
y@!\'y5v)?sz q0public class test163 {51Testing软件测试网W] m4E!l
    public static void main(String[] args) throws InterruptedException {
dHl3s+IeV0        // 启动浏览器,进入163邮箱首页
/\6aA D`@d0        //WebDriver driver = new InternetExplorerDriver();51Testing软件测试网~"jG] |FIl
        //WebDriver driver = new ChromeDriver();
b g%t:oM7Q\~5}6d0        WebDriver driver = new FirefoxDriver();51Testing软件测试网P$n.fXbw]i;r
        driver.get("http://mail.163.com/");
2e*mD7vX;se ]0       
e'lX^ }u/Ff0        Thread.sleep(5000);51Testing软件测试网%^F X1[4lW
        // 输入用户名密码,登录邮箱
Ie9a4lK U7t0        WebElement youxiangzhanghao_element = driver.findElement(By.id("idInput"));51Testing软件测试网 ^8{;lRe1vI1i,Z
        youxiangzhanghao_element.clear();
6^gon H J0  
aU&a sB e6JT`,H0        //邮箱用户名          youxiangzhanghao_element.sendKeys("selenium");
^e/HK^ P c {0Er0 51Testing软件测试网8Cxpo dX*R
//邮箱密码     51Testing软件测试网 @]mj nU
        WebElement mima_element = driver.findElement(By.id("pwdInput"));51Testing软件测试网 gJ!O _)@9n
        mima_element.sendKeys("123654");
$iF[5kS-ggqV`#@C0       51Testing软件测试网@?d$z2GCo"x
       51Testing软件测试网:z [ WoK _
        WebElement denglu_element = driver.findElement(By.id("loginBtn"));51Testing软件测试网 D|/g%ri&YA$C
        denglu_element.click();
N |^:vh'P D ]0       51Testing软件测试网Tl2_`q
        Thread.sleep(10000);
*rMR$CZ(F-m0        //  写信
x.y`c4mja0        //WebElement xiexin_element = driver.findElement(By.id("_mail_component_82_82"));51Testing软件测试网I5QHg2O
        WebElement xiexin_element = driver.findElement(By.xpath("//span[contains(.,'写 信')]"));
rZ*e|fLS0        xiexin_element.click();
2fX{`N|6gD7H0       51Testing软件测试网? B5c Pk}
        WebElement shoujianren_element = driver.findElement(By.className("nui-editableAddr-ipt"));51Testing软件测试网4S$E7j T:H~I]
        shoujianren_element.sendKeys("rob123654@163.com");
}oI9eLye0       51Testing软件测试网{^n.J+X
        WebElement zhuti_element = driver.findElement(By.id("objComposeSubject"));
Jbae_4{3j'W2q;c0        zhuti_element.sendKeys("test1");
!l5Bc$IEV k0       51Testing软件测试网?9WGyZ8DO9a
        WebElement youjianneirong_element = driver.switchTo().frame(driver.findElement(By.className("APP-editor-iframe"))).findElement(By.className("nui-scroll"));
I@ @4U ?t-S0        youjianneirong_element.sendKeys("123456");51Testing软件测试网*d7_B Cvwo"g
       51Testing软件测试网.`4xwb3[8b!^G
        driver.switchTo().defaultContent();51Testing软件测试网6Au$L5f R8Qt1w-^
       51Testing软件测试网RhT6KTh g:j
        // 发送邮件51Testing软件测试网'Y.\c1|beeZ Dq
        WebElement fasong_element = driver.findElement(By.xpath("//span[contains(.,'发 送')]"));
2O Hi3Ot0        fasong_element.click();
(H#TF_e+A7I*wW0       
F5u[ Y ^!A0        Thread.sleep(5000);51Testing软件测试网[hEuR?/jT f
       
M [5RV@_Z~wc*`0        WebElement tuichu_element = driver.findElement(By.linkText("退出"));
%H*twE&R [0        tuichu_element.click();51Testing软件测试网N#zv+p5]|sS8T
      
;P vY9_(kz0        driver.close();51Testing软件测试网!y hz0n7WA;Y
    }
"S$qU$k7g$j {051Testing软件测试网Bj!O-YX!J"r
}
51Testing软件测试网M6G$@,o0H w;vgT};cq

TAG:

 

评分:0

我来说两句

Open Toolbar