Michael Ma
Michael Ma

Reputation: 29

How does the firebug identify the unique css path for selenium?

When scripting automation with Selenium, I tried to locate a required web element with css selector, and I used the firebug to get the unique css path for that element. However, I was surprise since sometimes the firebug give me an incorrect css path although it works with selenium indeed.

<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>

I need the span which under the third tr whose class name is "bg_small_yellow". However, the firebug give me the unique css path as "tr.bg_small_yellow:nth-child(4) > td:nth-child(2) .topictitle > a:nth-child(1)", you see there are only 3 bg_small_yellow in total. where is the 4th one? How does it work?

Upvotes: 1

Views: 59

Answers (1)

Mohsin Awan
Mohsin Awan

Reputation: 1172

You can use unique X Paths to access web elements.

Selenium Command

Hope the above mentioned link helps to solve your problem!

Upvotes: 1

Related Questions