0

当我运行此代码时:

        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']"));

我收到此错误:

org.openqa.selenium.InvalidSelectorException:无法评估 xpath 表达式 '//input[contains(@id,'name']' 有关此错误的文档,请访问: http://seleniumhq.org/exceptions/invalid_selector_exception。 html构建信息:版本:'2.20.0',修订:'16008',时间:'2012-02-28 15:00:40' 系统信息:os.name:'Windows 7',os.arch:'x86 ',os.version:'6.1',java.version:'1.7.0_03'

这是我的 selenium IDe 源代码:

<?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>

谢谢

4

1 回答 1

2

我认为这是括号不匹配的简单案例。

你有"//input[contains(@id,'name']"

而不是使用它更改为"//input[contains(@id,'name')]"

于 2013-02-02T13:44:12.250 回答