Abbas Ali Husain
Abbas Ali Husain

Reputation: 195

I want to convert given Xpath into CSS

I want to convert the //input[@id=(//label[text()='Search for:']/@for)] to Css selector in selenium

Following is the HTML

<td class="mstrSearchFieldSearchBox">
    <div title="" class="mstrTextBoxWithIcon" id="id_mstr56" style="display: block;">
        <div class="mstrTextBoxWithIconCaption">
            <label for="id_mstr56_txt">Search for:</label>
        </div>
        <table cellspacing="0" cellpadding="0" class="mstrTextBoxWithIconTable">
            <tbody>
                <tr>
                    <td class="mstrTextBoxWithIconCellInput">
                        <div>
                            <input maxlength="" onclick="if (mstr.utils.ISW3C) {this.focus();}" onkeypress="return mstr.behaviors.TextBoxWithIcon.onkeypress(arguments[0], self, 'id_mstr56', this.value)" name="id_mstr56_txt" style="background-color: rgb(255, 255, 255);" id="id_mstr56_txt" size="" type="text">
                        </div>
                    </td>
                    <td class="mstrTextBoxWithIconCellIcon">
                        <div class="mstrToolButtonRoundedRight" style="background-position: left center;">
                            <input type="button" title="Search" onmouseout="mstr.behaviors.ToolButtonRounded.unhover(this.parentNode)" style="background-position: left center; cursor: pointer;" class="mstrBGIcon_tbSearch" src="../images/1ptrans.gif" onmouseover="mstr.behaviors.ToolButtonRounded.hover(this.parentNode)" onclick="mstr.behaviors.TextBoxWithIcon.fire('id_mstr56', this.parentNode.parentNode.previousSibling.childNodes[0].childNodes[0].value);return false;">
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</td>

Upvotes: 1

Views: 187

Answers (2)

santhosh kumar
santhosh kumar

Reputation: 2019

I hope you are trying to identify the element with tagName "input" and title with "search". We can identify the element by css as below,

 "input[type='button'][title='search']"

Also, we are not having any "id" attribute under tagname "input". How does your xpath works?

Upvotes: 0

Brydenr
Brydenr

Reputation: 798

Try using the CSS selector 'label[for="id_mstr56_txt"]'. As long as there is only one label with a for attribute of "id_mstr56_txt", this should work.

Upvotes: 1

Related Questions