Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I am trying to use SeleniumRC to test my GWT App and am trying to match elements using CSS selectors.

I want to count the number of enabled buttons in the following HTML.

A button is enabled if it is under a <td> with class="x-panel-btn-td " and disabled if it is under a <td> with class="x-panel-btn-td x-hide-offsets".

So basically, I want to retrieve the number of buttons under all <td>s with the class x-panel-btn-td.

<table cellspacing="0">

    <tbody>

    <tr>

        <td id="ext-gen3504" class="x-panel-btn-td ">

            <em unselectable="on">

                <button id="ext-gen3506" class="x-btn-text" type="button">OK</button>

            </em>

        </td>

        <td id="ext-gen3512" class="x-panel-btn-td x-hide-offsets">

            <em unselectable="on">

                <button id="ext-gen3506" class="x-btn-text" type="button">Yes</button>

            </em>

        </td>

        <td id="ext-gen3520" class="x-panel-btn-td">

            <em unselectable="on">

                <button id="ext-gen3506" class="x-btn-text" type="button">No</button>

            </em>

        </td>

        <td id="ext-gen3528" class="x-panel-btn-td x-hide-offsets">

            <em unselectable="on">

                <button id="ext-gen3506" class="x-btn-text" type="button">Cancel</button>

            </em>

        </td>

    </tr>

    </tbody>

</table>

1 Answer

0 votes
by (62.9k points)

As far as I am aware you can't do this using CSS selector, but there is a command in Selenium for counting by XPath. Use the following command will check that there are two disabled-buttons:

verifyXpathCount | //td[contains(@class, 'x-hide-offsets')]//button | 2

In Selenium RC (Java), use the below code:

assertEquals(selenium.getXpathCount("//td[contains(@class, 'x-hide-offsets')]//button"), 2);

Browse Categories

...