When working on automating scripts with Selenium, I encountered a situation where I needed to locate a specific web element using a css selector. I relied on Firebug to provide me with the unique css path for that element. Surprisingly, there were instances where Firebug generated an incorrect css path, even though it still worked with Selenium.
<table width="100%" cellspacing="1" cellpadding="4" border="0" class="forumline">
<tbody><tr>
<th nowrap="nowrap" height="25" align="center" colspan="2" class="thcornerl"> Topic </th>
<th width="50" nowrap="nowrap" align="center" class="thtop"> Answers </th>
<th width="100" nowrap="nowrap" align="center" class="thtop"> Author </th>
<th width="50" nowrap="nowrap" align="center" class="thtop"> Views </th>
<th nowrap="nowrap" align="center" class="thcornerr"> Last message </th>
</tr>
<!-- TOPICS LISTING -->
<tr class="bg_small_yellow">
<td width="20" valign="middle" align="center" class="row1Announce"> <img alt="" src="/jforum/images/transp.gif" class="icon_folder_announce">
<span class="topictitle">
<a href="/jforum/posts/list/2.page">
Support JForum - Please read
</a>
</span>
</td>
<td valign="middle" align="center" class="row2Announce"><span class="postdetails">0</span></td>
<td valign="middle" align="center" class="row3Announce">
<span class="name"><a href="/jforum/user/profile/2.page">Admin</a></span>
</td>
<td valign="middle" align="center" class="row2Announce"><span class="postdetails">4</span></td>
<td valign="middle" nowrap="nowrap" align="center" class="row3Announce">
<span class="postdetails">20/03/2016 13:58:24<br>
<a href="/jforum/user/profile/2.page">Admin</a>
<a href="/jforum/posts/list/2.page#2"><img border="0" alt="[Latest Reply]" src="/jforum/templates/default/images/icon_latest_reply.gif"></a></span>
</td>
</tr>
<tr class="bg_small_yellow">
<td width="20" valign="middle" align="center" class="row1"> <img alt="" src="/jforum/images/transp.gif" class="icon_folder">
<span class="topictitle">
<a href="/jforum/posts/list/3.page">
[Poll]
Which one is your favorite?
</a>
</span>
</td>
<td valign="middle" align="center" class="row2"><span class="postdetails">0</span></td>
<td valign="middle" align="center" class="row3">
<span class="name"><a href="/jforum/user/profile/3.page">yinzhenzhixin</a></span>
</td>
<td valign="middle" align="center" class="row2"><span class="postdetails">8</span></td>
<td valign="middle" nowrap="nowrap" align="center" class="row3">
<span class="postdetails">20/03/2016 14:34:25<br>
<a href="/jforum/user/profile/3.page">yinzhenzhixin</a>
<a href="/jforum/posts/list/3.page#4"><img border="0" alt="[Latest Reply]" src="/jforum/templates/default/images/icon_latest_reply.gif"></a></span>
</td>
</tr>
<<!-- END OF TOPICS LISTING -->
<tr align="center">
<td valign="middle" height="28" align="right" colspan="6" class="catbottom">
<table cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td align="center"><span class="gensmall"> </span></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
I was specifically looking for the span element under the third tr with the "bg_small_yellow" class. However, the css path provided by Firebug identified it as "tr.bg_small_yellow:nth-child(4) > td:nth-child(2) .topictitle > a:nth-child(1)", even though there are only 3 instances of "bg_small_yellow". Why is this happening and how does it function?