DemoUseFirefox

package demo;


import java.io.File;
import java.io.IOException;


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.firefox.FirefoxProfile;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.reporters.EmailableReporter;


public class DemoUseFirefox {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.bin","D:\\firefox\\firefox.exe");
File file=new File(".\\res\\firebug-1.12.0a3.xpi");
FirefoxProfile firefoxProfile=new FirefoxProfile();
try {
firefoxProfile.addExtension(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.12.0a3");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
// driver.navigate().to("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Selenium");
element.submit();
System.out.println("Page title is " + driver.getTitle());
new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("Selenium");
}
});


System.out.println("page title is :" + driver.getTitle());
driver.quit();
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章