【问题标题】:Selenium: Unable to locate element by it's containSelenium:无法通过包含来定位元素
【发布时间】:2013-02-02 13:33:30
【问题描述】:

当我运行这段代码时:

        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>

谢谢

【问题讨论】:

    标签: java xpath selenium-webdriver


    【解决方案1】:

    我认为这是括号不匹配的简单情况。

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

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

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多