简单实现优酷搜索,并打印出搜索结果

上一篇 / 下一篇  2012-10-29 10:04:32

[如需转载,请在转载时注明出处,并保证本文的完整性]
package com.test;
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.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class TestYouKu{
    public static void main(String[] args) {
        WebDriver driver= new FirefoxDriver();   //创建一个WebDriver实例,启动firefox浏览器
         driver.get(“http://www.youku.com”);     // 访问优酷
        WebElement element= driver.findElement(By.name(“q”));    // 找到文本框
         element.sendKeys(“泡芙小姐”);     // 输入搜索关键字
         element.submit();   //提交表单 WebDriver会自动从表单中查找提交按钮并提交
        System.out.println(“Page title is: ” + driver.getTitle());   // 检查页面title
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
             public Boolean apply(WebDriver d) {
                 return d.getTitle().toLowerCase().startsWith(“泡芙小姐”);
             }
        });       // 优酷查询结果是通过javascript动态呈现的.
                  // 设置页面等待10秒超时
        System.out.println(“Page title is: ” + driver.getTitle());   // 显示查询结果title
         driver.quit();   //关闭浏览器
    }
}

欢迎转载,请注明转自:测试之路-My Test Space
本文链接: 简单实现优酷搜索,并打印出搜索结果


TAG:

 

评分:0

我来说两句

Open Toolbar