import java.util.ArrayList;
import java.util.List;
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.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
public class FireFoxRunner {
static WebDriver driver;
static boolean flag;
// 新房销售状态单选下拉框这个失败了
public void getStuta() {
Select userSelect = new Select(driver.findElement(By.id("openTimeWord")));
userSelect.selectByVisibleText("下月开盘");
}
public static void main(String[] args) throws InterruptedException {
FireFoxRunner fr = new FireFoxRunner();
fr.initwebderiver();
try {
Thread.sleep(3000);
fr.login();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("start firefox browser succeed...");
}
private void initwebderiver() {
System.setProperty("webdriver.firefox.bin", "C://Program Files (x86)//Mozilla Firefox//firefox.exe");
driver = new FirefoxDriver();
driver.get("http://10.100.3.2/mainsite/src/html/login/login.html");
}
// 账号密码登录凤凰会
public void login() throws InterruptedException {
driver.findElement(By.id("username")).sendKeys("yc003");
driver.findElement(By.id("password")).sendKeys("a123456"); // 点击登录
Thread.sleep(3000);
driver.findElement(By.id("login-btn")).click();
Thread.sleep(3000);
String handle = driver.getWindowHandle();
// 获取所有页面的句柄,并循环判断不是当前的句柄
for (String temhandle : driver.getWindowHandles()) {
if (!temhandle.equals(handle))
driver.close();
driver.switchTo().window(temhandle);
}
gotostartsendpaint();
}
// 测试百度的搜素功能
private void search() {
driver.get("https://www.baidu.com/");
driver.findElement(By.id("kw")).sendKeys("北京大学");
driver.findElement(By.id("su")).click();
}
private void gotostartsendpaint() throws InterruptedException {
driver.get("http://10.100.3.2/output/output/sysmgmt/userMgmt");
// driver.findElement(By.linkText("用户中心")).click();
driver.findElement(By.linkText("添加用户")).click();
driver.findElement(By.id("ivu-input")).sendKeys("155109909009");
driver.findElement(By.id("ivu-input")).sendKeys("史新发");
driver.findElement(By.id("ivu-input")).sendKeys("研发部门");
driver.findElement(By.className("bw-btn margin")).click();
downloadfile();
/*
* List<WebElement> list =
* driver.findElements(By.className("openArea")); list.get(0).click();
*/
// driver.findElement(By.xpath(".//*[@id='btn_submit0']")).click();
try {
Thread.sleep(9000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//下载文件
private void downloadfile() {
driver.findElement(By.id("bw-btn bw-btn-first margin")).click();
}
//批量导入数据
private void importfile(){
driver.findElement(By.id(“bw-btn bw-btn-first margin”)).click();
}
//管理角色
public void managejuese(){
driver.findElement(By.id(“ivu-menu-item”)).click();
driver.findElement(By.id("bw-btn bw-btn-first margin")).click();
driver.findElement(By.id("bw-btn bw-btn-first margin")).click();
}
// 鼠标的操作事件
public void action() throws InterruptedException {
// 左击
Actions action = new Actions(driver);
WebElement test1item = driver.findElement(By.partialLinkText("门头沟楼盘"));
// action.doubleClick(test1item).perform();双击
// action.moveToElement(test1item).perform();拖动
// action.contextClick(test1item).perform();右击
// action.click(test1item).perform();左击
Thread.sleep(4000);
}
}
1.byclassname,byid的目标不能包含空格,不然会报错
2.firepath的使用必须依赖firebug的安装