package com.selenium1;
import com.thoughtworks.selenium.*;
public class Selenium1Class {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "https://www.baidu.com/");
selenium.start();
//京东登录 页面
selenium.open("https://www.jd.com/");
selenium.click("link=你好,请登录");
selenium.waitForPageToLoad("30000");
// System.out.println(selenium.getConfirmation());
// selenium.chooseOkOnNextConfirmation();
System.out.println("检查是否成功进入用户登录页面:"+"https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F".equals(selenium.getLocation()));
selenium.click("link=exact:忘记密码?");
selenium.waitForPageToLoad("30000");
System.out.println("检查是否成功进入忘记密码页面:"+"http://safe.jd.com/findPwd/index.action".equals(selenium.getLocation()));
selenium.goBack();
//Thread.sleep(2000); //挂起线程2000ms
selenium.waitForPageToLoad("30000");
selenium.type("id=loginname", "");
selenium.click("id=loginsubmit");
//System.out.println(selenium.getBodyText());
// Thread.sleep(2000);
System.out.println("弹出提示“请输入账户名和密码”:"+selenium.isTextPresent("请输入账户名和密码"));
selenium.type("id=loginname", "13809047980");
selenium.click("id=loginsubmit");
System.out.println("弹出提示“请输入密码”:"+selenium.isTextPresent("请输入密码"));
selenium.type("id=loginname", "");
selenium.type("id=nloginpwd", "@a111111");
selenium.click("id=loginsubmit");
System.out.println("弹出提示“请输入账户名”:"+selenium.isTextPresent("请输入账户名"));
selenium.type("id=loginname", "13809047980");
selenium.type("id=nloginpwd", "1111111");
selenium.click("id=loginsubmit");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("弹出提示“账户名与密码不匹配,请重新输入”:"+selenium.isTextPresent("账户名与密码不匹配,请重新输入"));
selenium.type("id=loginname", "13809047980");
selenium.type("id=nloginpwd", "@a111111");
selenium.click("id=loginsubmit");
selenium.waitForPageToLoad("30000");
System.out.println(selenium.getText("id=ttbar-login"));
System.out.println("成功登录并跳转到首页,操作上栏上出现,fod06234 退出:"+"fod06234 退出".equals(selenium.getText("id=ttbar-login")));
//多窗口处理
/*selenium.open("http://www.baidu.com");
//selenium.open("http://www.baidu.com/index.php?tn=monline_3_dg");
selenium.click("name=tj_login");
// selenium.selectPopUp(selenium.getAllWindowNames()[1]);
//selenium.click("link=立即注册");
String titles[]=selenium.getAllWindowTitles();
System.out.println("所有窗口的标题分别为:");
for(int i=0;i<titles.length;i++)
{
System.out.println(titles[i]);
}*/
//下拉框选择
/*selenium.open("http://tieba.baidu.com/");
selenium.click("link=高级搜索");
selenium.waitForPageToLoad("2000");
selenium.select("name=sm", "label=按相关性排序");
String title=selenium.getTitle();
System.out.println(title);
String url=selenium.getLocation();
System.out.println(url);*/
//单击搜索
/* selenium.open("http://www.baidu.com");
//selenium.waitForPageToLoad("3000");
selenium.type("id=kw", "selenium");
selenium.click("id=su");*/
//回退操作
/* selenium.open("http://www.jd.com");
try{
Thread.sleep(3000);
}
catch (InterruptedException e){
e.printStackTrace();
}
selenium.goBack();*/
selenium.close(); //关闭测试所用的浏览器
selenium.stop(); //中止当前对Selenium服务器的会话,并关闭Selenium控制界面
//selenium.shutDownSeleniumServer(); //关闭Selenium服务器
}
}