如何使用硒类型的方法?

zfr*_*cus 3 java selenium

我有一个带有输入文本字段的JSP页面.

<table>
    <tr>
        <td><input type="text" id="searchText" name="searchInput"/></td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我写了一个selenium测试用例,用于验证搜索输入文本是否存在.

public class UIRecipeListTest extends SeleneseTestBase {

    @Before
    public void setup() {
        WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File(
                "C:\\Program Files (x86)\\Mozilla Firefox 3.6\\firefox.exe")), new   FirefoxProfile());

        String baseUrl = "http://localhost:8080/RecipeProject/";
        selenium = new WebDriverBackedSelenium(driver, baseUrl);
    }

    @Test
    public void testShowRecipes() {
        verifyTrue(selenium.isElementPresent("searchText"));    
        selenium.type("searchText", "salt");
    }
}
Run Code Online (Sandbox Code Playgroud)

}

verifyTrue测试返回true.但是,selenium.type测试失败并出现此错误:com.thoughtworks.selenium.SeleniumException:找不到元素searchText

我该怎么做才能使测试工作?

谢谢.

dda*_*son 8

第一个参数需要是选择器. searchText不是有效的CSS或xpath选择器.

你会用类似的东西 selenium.type("css=input#searchText", "salt");

还想指出你似乎是在Selenium的2版本之间.

selenium.type(String,String)来自Selenium 1 API.你应该保持1个版本,如果它将是Selenium 2,你需要做类似的事情,

WebElement element = driver.findElement(By.id("searchText")) 并使用 element.sendKeys("salt");

来源: Selenium API类型(String,String)