2

I am not able click on Pending Verification list item

<li id="ctl00_MainContent_ASPxSplitter1_ASPxNavBar_I0i0_" class="dxnb-item dxnb-link dxnb-itemSelected" onclick="__doPostBack('ctl00$MainContent$ASPxSplitter1$ASPxNavBar','CLICK:0i0')">
<span class="dx-vam">Pending Verification</span>
</li>

after execute my script it gives following error:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='ctl00_MainContent_ASPxSplitter1_0']"}
  (Session info: chrome=55.0.2883.87)
  (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 155 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'WIN10EDS1', ip: '10.0.0.7', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=C:\WINDOWS\TEMP\scoped_dir1624_29660}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: d74af3d7991c00c570b7f5cd95dd0e07
*** Element info: {Using=xpath, value=.//*[@id='ctl00_MainContent_ASPxSplitter1_0']}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
    at WorkAlerts.Links.SubLinks(Links.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
  • Try with : your_element.sendKeys("Pending Verification"); – NarendraC Jan 13 '17 at 6:55
  • Could you also add the test code, this could help finding your issues. – Niels van Reijmersdal Jan 14 '17 at 14:45
2

The error is occurred because the compiler couldn't find the the li element. May be you can wait for the element to appear as:

WebDriverWait wait = new WebDriverWait(driver,5);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.loctor(item))); 

But, if you want to click on the text in the span element you can try the following:

driver.findElement(By.xpath("//span[contains(text(), "Pending Verification")]")).click();

or

driver.findElement(By.xpath(".//*[@id='ctl00_MainContent_ASPxSplitter1_ASPxNavBar_I0i0_']/span")).click();
  • Probably the issue is with waiting as most UI testing issues are – Niels van Reijmersdal Jan 14 '17 at 14:34
  • Hi @NielsvanReijmersdal, yes it may the case – the_coder Jan 14 '17 at 15:38
0

The error says your element cannot not be found on the time you request it.

Unable to locate element: {"method":"xpath","selector":".//[@id='ctl00_MainContent_ASPxSplitter1_0']"}

The selector does not match your HTML example: ctl00_MainContent_ASPxSplitter1_ASPxNavBar_I0i0_ vs ctl00_MainContent_ASPxSplitter1_0

Partial matches and or difference do not work, you need exact matches, unless you make your selector smarter with wildcards: https://blog.mozilla.org/webqa/2013/09/26/writing-reliable-locators-for-selenium-and-webdriver-tests/

Other things to check when debugging Selenium WebDriver issues:

  1. Is the selector correct, load the page in chrome, use the selector in the console with $x('your selector'). Also check: https://stackoverflow.com/questions/22571267/how-to-verify-an-xpath-expression-in-chrome-developers-tool-or-firefoxs-firebug
  2. Is the element there on the time you check, since findelement does not wait for the element. If it is not there it just throws this exception NoSuchElement, you have to implement a wait: https://stackoverflow.com/questions/20077860/selenium-webdriver-explicit-wait
0

Isn't your ID generated anyhow? You could try searching the element using prefix/suffix selectors, like:

driver.FindElement(By.CssSelector("li[id^='id_prefix_']"));
driver.FindElement(By.xpath(.//*[@idˆ='id_prefix_']));
driver.FindElement(By.CssSelector("li[id$='id_suffix_']"));
driver.FindElement(By.xpath(.//*[@id$='id_suffix_']));

You might want to check https://saucelabs.com/resources/articles/selenium-tips-css-selectors, section SUB-STRING MATCHES.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.