I am new to testing and need some help on Xpath for following code :
InnerHTML of the element:
<img class="icon" src="custom/icons/Injury.png">
<span class="buttonText"><span class="title">An injury</span></span>
<span class="title">An injury</span>
I want to click on "An injury", have tried below xpath but its not working
driver.findElement(By.xpath(".//span[text()='An injury']")).click();
<div id="pageLayout-eLeType-AFBWtFlqgByDxQjVusTPqEu0-bMs-AFBWtFlqgByDxQjVusTPqEuw" class="formCell button80Percent" style="width:48.0%;">
<div class="dashboardLinksContainer">
<div title="" class="dashboardLink linkAsButton">
<a href="/QUASAR/new/Incident" onclick="userFavourites.recordVisit('Incident', 'anVtcENvbW1hbmQoJz9jb21tYW5kPW5ldyZicGlkPUFCTnlsR0dYTWpRMk9EazJNREkwTXpNNCZ0aXRsZT0iSW5jaWRlbnQiJyk7');jumpCommand('?command=new&bpid=ABNylGGXMjQ2ODk2MDI0MzM4&title="Incident"');return false;"><img class="icon" src="custom/icons/Injury.png">
<span class="buttonText">
<span class="title">An injury</span>
</span>
</a>
</div>
</div>
<div class="clear"></div>
</div>
<div id="pageLayout-eLeType-AFBWtFlqgByDxQjVusTPqEu3-bMs-AFBWtFlqgByDxQjVusTPqEuw" class="formCell button80Percent" style="width:48.0%;">
<div class="dashboardLinksContainer">
<div title="" class="dashboardLink linkAsButton">
<a href="/QUASAR/new/Incident" onclick="userFavourites.recordVisit('Incident', 'anVtcENvbW1hbmQoJz9jb21tYW5kPW5ldyZicGlkPUFCTnlsR0dYTWpRMk9EazJNREkwTXpNNCZ0aXRsZT0iSW5jaWRlbnQiJyk7');jumpCommand('?command=new&bpid=ABNylGGXMjQ2ODk2MDI0MzM4&title="Incident"');return false;">
<img class="icon" src="custom/icons/Damage.png">
<span class="buttonText"><span class="title">Damage or loss to property or asset</span>
</span>
</a>
</div>
</div>
<div class="clear"></div>
</div>
Here is the 2 html code and there are about 8 more and all have same span class >buttonText and Span class = title with just different title names

xpath-2.0tag? Selenium doesn't support XPath 2.0. Also let us know which element exactly you want to click: provided HTML sample differs from HTML on attached picture - Andersson<a>tag instead of the<span>tag? There's an inline JavaScript registered to the<a>tag onclick event. - Mincong Huang