gpt4 book ai didi

html - firebug 如何识别 selenium 的唯一 css 路径?

转载 作者:行者123 更新时间:2023-11-28 15:55:40 26 4
gpt4 key购买 nike

当使用 Selenium 编写自动化脚本时,我尝试使用 css 选择器定位所需的 Web 元素,然后使用 firebug 获取该元素的唯一 css 路径。然而,我很惊讶,因为有时 firebug 会给我一个不正确的 css 路径,尽管它确实适用于 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">&nbsp;Topic&nbsp;</th>
<th width="50" nowrap="nowrap" align="center" class="thtop">&nbsp;Answers&nbsp;</th>
<th width="100" nowrap="nowrap" align="center" class="thtop">&nbsp;Author&nbsp;</th>
<th width="50" nowrap="nowrap" align="center" class="thtop">&nbsp;Views&nbsp;</th>
<th nowrap="nowrap" align="center" class="thcornerr">&nbsp;Last message&nbsp;</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">&nbsp;</span></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>

我需要在类名为“bg_small_yellow”的第三个 tr 下的跨度。然而,firebug 给我唯一的 css 路径为“tr.bg_small_yellow:nth-child(4) > td:nth-child(2) .topictitle > a:nth-child(1)”,你看只有 3 个总共 bg_small_yellow。第4个在哪里?它是如何工作的?

最佳答案

您可以使用唯一的 X 路径来访问网络元素。

Selenium Command

希望上述链接能帮助解决您的问题!

关于html - firebug 如何识别 selenium 的唯一 css 路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41198345/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com