获取错误 "Unable to Locate element"
Getting error "Unable to Locate element"
我正在使用 selenium webdriver 2.53 和 firefox 43.0.1。我将 ide 测试用例导出到 TestNG 并发现错误 "Unable to Locate element"
<a href="javascript:void(0);">
<i class="fa fa-user"></i>
<span class="nav-label">My Profile</span>
<span class="fa arrow"></span>
</a>
org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"link text","selector":"My Profile"}
By.linkText
不适用于 <span>
标签,仅适用于 <a>
标签。使用 xpath
代替
By.xpath("//span[contains(., 'My Profile')]")
试试这个 xpath。
使用 <span>
标签的 text
方法。
//span[contains(text(), 'My Profile')]
我正在使用 selenium webdriver 2.53 和 firefox 43.0.1。我将 ide 测试用例导出到 TestNG 并发现错误 "Unable to Locate element"
<a href="javascript:void(0);">
<i class="fa fa-user"></i>
<span class="nav-label">My Profile</span>
<span class="fa arrow"></span>
</a>
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"My Profile"}
By.linkText
不适用于 <span>
标签,仅适用于 <a>
标签。使用 xpath
代替
By.xpath("//span[contains(., 'My Profile')]")
试试这个 xpath。
使用 <span>
标签的 text
方法。
//span[contains(text(), 'My Profile')]