Belin
Belin

Reputation: 353

Selenium: Unable to locate element by it's contain

When i'm running this code:

        driver = new HtmlUnitDriver();
        baseUrl = "http://localhost:8080/alooh-paid";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);        
           WebElement loginElement =driver.findElement(By.xpath("//input[contains(@id,'name']"));

i'm getting this error :

org.openqa.selenium.InvalidSelectorException: The xpath expression '//input[contains(@id,'name']' cannot be evaluated For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html Build info: version: '2.20.0', revision: '16008', time: '2012-02-28 15:00:40' System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_03'

This is my selenium IDe source:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhost:8080/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>/alooh-paid/login.jsf</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>//input[@id='j_idt11:j_idt14:name']</td>
    <td>admin</td>
</tr>
<tr>
    <td>type</td>
    <td>//input[@id='j_idt11:j_idt14:password']</td>
    <td>12563</td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>id=j_idt11:j_idt14:register</td>
    <td></td>
</tr>

</tbody></table>
</body>
</html>

Thank

Upvotes: 0

Views: 1370

Answers (1)

Aniket Lawande
Aniket Lawande

Reputation: 131

I think it's a simple case of parentheses mismatch.

You have "//input[contains(@id,'name']"

Instead of using it change it to "//input[contains(@id,'name')]"

Upvotes: 2

Related Questions