WebDriver ???????
???????????? ???????[ 2013/1/21 10:30:51 ] ????????
public class Login {
private WebDriver webDriver;
private String baseUrl;
private Logger logger = LoggerFactory.getLogger(this.getClass());
private WebElement element;
public void openBrowser() throws Exception{
webDriver = new FirefoxDriver();
webDriver.get(baseUrl);
}
public void clickLoginLink(){
try {
baseUrl = "http://www.lovo.cn/";
this.openBrowser();
element = webDriver.findElement(By.linkText("???"));
if(element != null){
element.click();
if(webDriver.findElement(By.id("logusername")) != null){
logger.info("?????????????");
}else{
logger.error("???????????");
}
}else{
logger.error("?????????????!!!");
}
} catch (Exception e) {
e.printStackTrace();
logger.error("????δ?????");
}
}
public void login(){
this.webDriver.findElement(By.id("logusername")).clear();
this.webDriver.findElement(By.id("logusername")).sendKeys("138****035");
this.webDriver.findElement(By.id("logpassword")).clear();
this.webDriver.findElement(By.id("logpassword")).sendKeys("123456");
this.webDriver.findElement(By.id("logimageCheck")).clear();
this.webDriver.findElement(By.id("logimageCheck")).sendKeys("5rkz");
this.webDriver.findElement(By.cssSelector("span.btntext")).click();
this.webDriver.findElement(By.cssSelector("div.text")).click();
if(this.webDriver.findElement(By.cssSelector("BODY")).getText().matches("^[\s\S]* ??????[\s\S]*$")){
this.logger.info("????????");
}else{
this.logger.error("???????");
}
}
public static void main(String[] args){
Login login = new Login();
login.clickLoginLink();
login.login();
}
}
??????????firefox????????????а??firefox????????????????????firefox???????·????????????£?????????FirefoxBinary??????
???????????£?
public WebDriver openFirefox() throws Exception{
File file = new File("???firefox????·??+firefox.exe"); //??????????????
FirefoxBinary firefoxBin = new FirefoxBinary(file);
WebDriver webDriver = new FirefoxDriver(firefoxBin??null);
return webDriver;
}
???????????setCapabilit??????
???????????£?
public WebDriver openFirefox() throws Exception{
DesiredCapabilities des = DesiredCapabilities.firefox();
des.setCapability("firefox_binary"?? "???firefox????·??+firefox.exe");
WebDirver webDriver = new FirefoxDriver(des);
return webDriver;
}
???????
????FirefoxDriver????7????????????ζ???????7?з?????firefox????????????7?????
FirefoxDriver()
FirefoxDriver(Capabilities desiredCapabilities)
FirefoxDriver(Capabilities desiredCapabilities?? Capabilities requiredCapabilities)
FirefoxDriver(FirefoxBinary binary?? FirefoxProfile profile)
FirefoxDriver(FirefoxBinary binary?? FirefoxProfile profile?? Capabilities capabilities)
FirefoxDriver(FirefoxBinary binary?? FirefoxProfile profile?? Capabilities desiredCapabilities?? Capabilities requiredCapabilities)
FirefoxDriver(FirefoxProfile profile)
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11