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

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

package com.test;51Testing软件测试网!d u S?n-z`
51Testing软件测试网UB6G5J|W
import java.util.List;
+E,kw%\8m0
s/hS"R5|/r0import org.openqa.selenium.By;51Testing软件测试网&H.c7A_ Y
import org.openqa.selenium.WebDriver;51Testing软件测试网/[#P}n\\uyO
import org.openqa.selenium.WebElement;
2w8b` K~BH0import org.openqa.selenium.chrome.ChromeDriver;
YX`P N2t#IN0import org.openqa.selenium.firefox.FirefoxDriver;51Testing软件测试网nR;JU4?-b(V`(b
import org.openqa.selenium.ie.InternetExplorerDriver;
X4xH0f-Y!td'D0import org.openqa.selenium.interactions.Actions;
X1LgN&y&S2gyl s051Testing软件测试网;@*dOjD M
public class test163 {
2{/lmH$?SG)N0    public static void main(String[] args) throws InterruptedException {51Testing软件测试网A&wy{2?2xQ~
        // 启动浏览器,进入163邮箱首页51Testing软件测试网;Z3D G5z!W
        //WebDriver driver = new InternetExplorerDriver();51Testing软件测试网u&B{)VFv d%G[8i;L
        //WebDriver driver = new ChromeDriver();51Testing软件测试网2y/VM AI5U!n
        WebDriver driver = new FirefoxDriver();51Testing软件测试网qlD L q D}#v
        driver.get("http://mail.163.com/");
|,e0`HPxx'N0       
\#uV]$J/RJ5[A0        Thread.sleep(5000);51Testing软件测试网8m.w+Q2@ ~
        // 输入用户名密码,登录邮箱51Testing软件测试网 n7Z~o wT?(X
        WebElement youxiangzhanghao_element = driver.findElement(By.id("idInput"));
4Dji0c,c^0        youxiangzhanghao_element.clear();51Testing软件测试网)S"^+f1r%|,e
  
t;d*t@O(k-U~5B0        //邮箱用户名          youxiangzhanghao_element.sendKeys("selenium");
b;Y2o^W$kw~3?0 
't?:@6z1\ a0//邮箱密码     
3H)S k+u7YpbG5Y$E0        WebElement mima_element = driver.findElement(By.id("pwdInput"));
9Vc e4XD1Ju)}o'X&~0        mima_element.sendKeys("123654");51Testing软件测试网L*}i @|
       51Testing软件测试网+J2j|B2v6kAq(?
       51Testing软件测试网aQhXV3V
        WebElement denglu_element = driver.findElement(By.id("loginBtn"));51Testing软件测试网K}7q:z/odh/Q_
        denglu_element.click();51Testing软件测试网+v%K([6iy_#{K
       
@Fe*J!JM0        Thread.sleep(10000);51Testing软件测试网8AQ5l8QAT
        //  写信51Testing软件测试网6}})Kq&t A
        //WebElement xiexin_element = driver.findElement(By.id("_mail_component_82_82"));51Testing软件测试网d`G(u W+ul
        WebElement xiexin_element = driver.findElement(By.xpath("//span[contains(.,'写 信')]"));51Testing软件测试网O]D5?2i j%Z
        xiexin_element.click();51Testing软件测试网5V~ L/kte_&@.K
       
5VC|h*l;L2C1W BW0        WebElement shoujianren_element = driver.findElement(By.className("nui-editableAddr-ipt"));
M1rg:c,IX0        shoujianren_element.sendKeys("rob123654@163.com");
R~,{'Eve/d7W$L0       
#Q&[ }%K;^$w0        WebElement zhuti_element = driver.findElement(By.id("objComposeSubject"));51Testing软件测试网)U Dn5T]q6r
        zhuti_element.sendKeys("test1");51Testing软件测试网u#l M*L%N$}
       
H%y Df%n%r(D+W"x0        WebElement youjianneirong_element = driver.switchTo().frame(driver.findElement(By.className("APP-editor-iframe"))).findElement(By.className("nui-scroll"));51Testing软件测试网~-I1kW0GGrk3I
        youjianneirong_element.sendKeys("123456");51Testing软件测试网;p3auo]9ppT
       51Testing软件测试网v ao ^$A(Y8P9E;f
        driver.switchTo().defaultContent();
GI'qo7EX*v+Ru0       
&p-Z.kU;l0        // 发送邮件
5t^#b~5b megV8V^|0        WebElement fasong_element = driver.findElement(By.xpath("//span[contains(.,'发 送')]"));
A*`V._ g$Jc?0        fasong_element.click();51Testing软件测试网}1bl]ZD
       51Testing软件测试网x(aR;xI#w,w
        Thread.sleep(5000);
H gBnI0       
hEy%Fm0?LUg2]0        WebElement tuichu_element = driver.findElement(By.linkText("退出"));
k9~L4wj]0        tuichu_element.click();
r*@6Zs!S0      
rTC-~hN'aA0        driver.close();
A I.Kk2g$C0    }51Testing软件测试网Q8d0@,_y#WFx]

2`1Su5QI*c_ mC0}
51Testing软件测试网F+~;cb#A4m}E@

TAG:

 

评分:0

我来说两句

Open Toolbar