当使用Selenium进行脚本自动化时,我尝试使用css选择器查找所需的web元素,然后使用firebug获取该元素的唯一css路径。然而,我很惊讶,因为有时萤火虫给我一个不正确的CSS路径,虽然它确实与硒一起工作。萤火虫如何识别硒的独特css路径?
<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>
<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/1.page">
Welcome to JForum
</a>
</span>
</td>
<td valign="middle" align="center" class="row2"><span class="postdetails">1</span></td>
<td valign="middle" align="center" class="row3">
<span class="name"><a href="/jforum/user/profile/2.page">Admin</a></span>
</td>
<td valign="middle" align="center" class="row2"><span class="postdetails">6</span></td>
<td valign="middle" nowrap="nowrap" align="center" class="row3">
<span class="postdetails">20/03/2016 14:09:51<br>
<a href="/jforum/user/profile/3.page">yinzhenzhixin</a>
<a href="/jforum/posts/list/1.page#3"><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>
我需要的跨度,其在第三个tr名下是“bg_small_yellow”。然而,萤火虫给我独特的CSS路径为“tr.bg_small_yellow:n-child(4)> td:n-child(2).topictitle> a:n-child(1)”,你看到只有3总共bg_small_yellow。第四个在哪里?它是如何工作的?
欢迎来到Stack Overflow!请阅读[问]。请提供您尝试过的代码以及执行结果,包括任何错误消息等。还请提供指向页面和/或相关HTML的链接。 – JeffC