У меня есть список элементов в теге nav. Я хочу нажать на первый элемент списка. Мой HTML приведен ниже:
<aside id="left-panel" style="overflow: visible;">
<div id="selectedBrand" class="custum-brand-info login-info">
<span class="dropdown">
</div>
<nav>
<ul id="sideNavigation">
<li>
<a onclick="showHideBrandmanagement(true);" href="/sentiment/view">
<i class="fa fa-lg fa-fw fa-thumbs-up"></i>
<span class="menu-item-parent">Sentiment</span>
</a>
</li>
</ul>
</nav>
Мой тестовый пример иногда терпел неудачу; мой тестовый пример прошел, но иногда он терпел неудачу. Я запускаю тестовый пример в безголовом режиме, используя XVFB.
should get the data within topic * FAILED *
[info] org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#left-panel nav #sideNavigation li:nth-child(9) #rAnalytics"} [info] Command duration or timeout: 10.06 seconds [info] For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html [info] Build info: version: '2.47.1', revision: 'unknown', time: '2015-07-30 11:02:44' [info] System info: host: 'knoldus-Vostro-2520', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-30-generic', java.version: '1.7.0_80' [info] *** Element info: {Using=css selector, value=#left-panel nav #sideNavigation li:nth-child(9) #rAnalytics} [info] Session ID: edc0a525-38bb-48b2-88c4-e1ad01265c15 [info] Driver info: org.openqa.selenium.firefox.FirefoxDriver [info] Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=41.0}] [info] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [info] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [info] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [info] at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [info] at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) [info] at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) [info] at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595) [info] at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348) [info] at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:437) [info] at selenium.professionalPlan.Topic$$anonfun$1$$anonfun$apply$mcV$sp$1.apply(Topic.scala:31) [info] ... [info] Cause: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#left-panel nav #sideNavigation li:nth-child(9) #rAnalytics"} [info] For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html [info] Build info: version: '2.47.1', revision: 'unknown', time: '2015-07-30 11:02:44' [info] System info: host: 'knoldus-Vostro-2520', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-30-generic', java.version: '1.7.0_80' [info] Driver info: driver.version: unknown [info] at .FirefoxDriver.prototype.findElementInternal_(file:///tmp/anonymous5218088375039490898webdriver-profile/extensions/[email protected]/components/driver-component.js:10667) [info] at .fxdriver.Timer.prototype.setTimeout/<.notify(file:///tmp/anonymous5218088375039490898webdriver-profile/extensions/[email protected]/components/driver-component.js:623) [1]I have tried Xpath, cssSelector, even I manually provide an id to first anchor tag, but my test case failed and I got an exception.