Skip to content

How can I use a Selenium type method?

I have a JSP page with an input text field.

        <td><input type="text" id="searchText" name="searchInput"/></td>

I wrote a Selenium test case that verifies that the search input text is present.

public class UIRecipeListTest extends SeleneseTestBase {

    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);

    public void testShowRecipes() {
        selenium.type("searchText", "salt");

The verifyTrue test returns true. However, the selenium.type test failed with this error:

com.thoughtworks.selenium.SeleniumException: Element searchText not found

What should I do to make the test work?


The first parameter needs to be a selector. searchText isn’t a valid CSS or XPath selector.

You would use something like selenium.type("css=input#searchText", "salt");.

I also wanted to point out that you seem to be going between two versions of Selenium.

selenium.type(String,String) is from the Selenium 1 API. You should keep to the 1 version, and if it’s going to be Selenium 2, you need to do something like,

WebElement element = driver.findElement("searchText"))

and use


Source: Selenium API type(String,String)