这篇可以不看,主要是为了以后的应用代码(传参)做铺垫。

import java.awt.Rectangle;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.imageio.ImageIO;

import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

public class Login {
public static int t = 1;


static WebDriver driver = new ChromeDriver();


public void Loginindex(String url,String user,String pass) throws InterruptedException{

driver.get(url);

// 用下面代码也可以实现
// driver.navigate().to("url");
// 获取 网页的 title
// System.out.println("1 Page title is: " + driver.getTitle());
// 通过 id 找到 input 的 DOM
// try{
// WebElement element0 =driver.findElement(By.xpath("//div[contains(@class,'user-info-mission-luckdraw-mask-body-close')]"));
// element0.click();
// }catch(Exception e){
// System.out.println("广告没有了");
// //System.exit(0);
// }
WebElement element = driver.findElement(By.xpath("//button[contains(@class,'Login')]"));
// 输入关键字
element.click();
Thread.sleep(3000);
WebElement frame = driver.findElement(By.xpath("//*[@id='C_maijia-login']/div/div/div/iframe"));
driver.switchTo().frame(frame);
WebElement element1 =driver.findElement(By.xpath("//input[@name='loginCode']"));
element1.sendKeys(user);
WebElement element2 =driver.findElement(By.xpath("//input[@name='loginPassword']"));
element2.sendKeys(pass);;
WebElement button =driver.findElement(By.xpath("//button[contains(.,'登录')]"));
button.click();
}


}

posted on 2016-03-17 11:30  testhua  阅读(700)  评论(0编辑  收藏  举报