【发布时间】:2016-12-28 23:15:10
【问题描述】:
我有这段代码
<a href="/iot/apply/device.do" id="subMenu1" class="fortification55"
onclick="$('#deviceinfo').hide()">Apply</a>
我正在尝试使用 href 链接
getDriver().findElement(By.name("subMenu1")).click();
但我得到了这个错误
org.openqa.selenium.NoSuchElementException: Unable to find element with name == subMenu1 (WARNING: The server did not provide any stacktrace information)
【问题讨论】:
-
我认为你应该使用
By.id("subMenu1") -
也可以直接使用
getDriver().findElement(By.linkText("Apply")).click(); -
你也可以使用xpaths:
//a[@id='subMenu1']或//a[text()='Apply'] -
您可以用作:
getDriver().findElement(By.className("fortification55")).click();
标签: selenium xpath onclick css-selectors webdriverwait