I'm trying to click on a link (Which looks like a tab button) using Xpath
but getting an error.
This is the html
snippet :
<div id="tile_8" style="height: 93px; width: 26%; background-color: rgb(45, 87, 19); color: white; position: relative; float: left; margin: 10px; padding: 5px; cursor: pointer; z-index: 1; border: 2px solid white;" class="divAppList-shadow" onmouseover="mouseOvering(event,'8')" onmouseout="mouseOuting(event,'8')">
<b>
<span style="font-size:medium; z-index:1; color:white;">Suggestion Scheme</span>
</b><br>
<span style="text-align:justify; z-index:1;color:white;">There is always a better way of doing a thing. You only can suggest it for us to Improve.</span>
</div>
I have tried the following code :
driver.findElement(By.xpath("/html/body/div[5]/div[2]/div")).click();
This is the Error :
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[5]/div[2]/div"}
(Session info: chrome=54.0.2840.87) (Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.10586 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 412 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700' System info: host: 'tmlpnedtp061674', ip: '172.22.84.78', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_101' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9), userDataDir=C:\Users\AMITPA~1.TTL\AppData\Local\Temp\scoped_dir11224_7493}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=54.0.2840.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}] Session ID: 2bb2aa6d378f2c0f6ec720a9ee87068c *** Element info: {Using=xpath, value=/html/body/div[5]/div[2]/div} 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 testProj001.CordysUpgradeDemo.main(CordysUpgradeDemo.java:19)
In the Screenshot as you can see i am trying to click on The Suggestion Scheme Button Link
HTML
code for mentioned button – Anderssonxpath
which would not be more stable, for better solution you need to share relevant HTML.. – Saurabh Gaur