Java使用Selelium的一个例子

public class TestUserRegister extends TestCase {

	public TestUserRegister() {

	}

	WebDriver driver;

	protected void setUp() throws Exception {
		System.out.println("setup before father class - before class");

		// driver = new FirefoxDriver();
		driver = new FirefoxDriver();

		// Adjust firefox window
		// JavascriptExecutor js = (JavascriptExecutor) driver;
		// js.executeScript("window.resizeTo(1280,heightscreen.)");
		// driver.get("http://localhost:8080/HelloStripes/index.jsp");
	}

	public void test1() {
		driver.findElement(By.id("message")).sendKeys("Test");
		driver.findElement(By.id("sayHello")).click();
		waitForLoad(By.id("HelloWorld"));
	}

	public void waitForLoad(final By elementBy) {
		WebDriverWait wait = (new WebDriverWait(driver, 30));
		wait.until(new ExpectedCondition<Boolean>() {
			public Boolean apply(WebDriver d) {
				boolean loadcomplete = d.findElement(elementBy).isDisplayed();
				return loadcomplete;
			}
		});
	}

}

你可能感兴趣的:(java,demo,例子,Selelium)