Supposing you have a HTML like this:
<html>
<head>
...</head>
<body>
<div style="background-color:#ccffcc">
<p>with <span style="font-weight:bold">javascript:selectday(</span></p>
<table id="with-it">
<tbody>
<tr><td><a HREF=''
onclick="javascript:selectday(14879,'10/18/2018'); return false;"
> 18</a></td></tr>
</tbody>
</table>
</div>
<div style="background-color:#ffcccc">
<p>without it</p>
<table id="without-it">
<tbody>
<tr><td> 14</td></tr>
</tbody>
</table>
</div>
</body>
</html>
I made 4 Test Objects as follows
’Page_Discussion 7278/with-it_td_a’ with a selector by xpath:
//table[@ id="with-it"]/tbody/tr/td/a
’Page_Discussion 7278/with-it_td_a_onclick’ with a selector by xpath:
//table[@ id="with-it"]/tbody/tr/td/a[starts-with(@ on-click,'javascript:selectday(')]
’Page_Discussion 7278/without-it_td_a’ with a selector by xpath:
//table[@ id="without-it"]/tbody/tr/td/a
’Page_Discussion 7278/without-it_td_a_onclick’ with a selector by xpath:
//table[@ id="without-it"]/tbody/tr/td/a[starts-with(@ on-click,'javascript:selectday(')]
(Don’t be confused with a white space character between ‘@’ and ‘id’. It should not be there, but I inserted it intensionally to work-around a markup problem of this forum.)
Then I made a Test Case like:
// following 2 lines will succeed
WebUI.verifyElementPresent(findTestObject('Page_Discussion 7278/with-it_td_a'), 10, FailureHandling.OPTIONAL)
WebUI.verifyElementPresent(findTestObject('Page_Discussion 7278/with-it_td_a_onclick'), 1, FailureHandling.OPTIONAL)
// following 2 lines will result in a warning message of WebElementNotFound
WebUI.verifyElementPresent(findTestObject('Page_Discussion 7278/without-it_td_a'), 1, FailureHandling.OPTIONAL)
WebUI.verifyElementPresent(findTestObject('Page_Discussion 7278/without-it_td_a_onclick'), 1, FailureHandling.OPTIONAL)
I would suggest that you would need this:
//table[...]/tbody/tr/td/a
But you wouldn’t need this:
//table[...]/tbody/tr/td/a[starts-with(@on-click,'javascript:selectday(')]
I mean verifying presence of element is enough to identify if any link is there in the table. No need to look at ‘javascript:selectday(’ portion specifically. These two xpath result the same.