1

I have a page with a list of check boxes. I want to click the check box which has a specified text. E.g. I want to click the check box which has the name "Use ocr variations" In the HTML the check box is above the Label tag. In firebug I can find the the label tag with the following XPath:

//div[@id="match_configuration_edit_match_tab_data_objects_fp_flags"]//label[contains(text(), "Use ocr variations")]

I would like to go 1 above to the input tag which has the check box. I have tried to use ancestor but that does not work

//div[@id="match_configuration_edit_match_tab_data_objects_fp_flags"]//label[contains(text(), "Use alias list to get variations")]/ancestor::input

What is the Xpath or CSS i could use to get to the checkbox?

The HTML is:

<div id="match_configuration_edit_match_tab_data_objects_fp_flags">
    <div class="gwt-Label matchruleheader">Gender and title flags</div>
        <span class="gwt-CheckBox" style="display: block;">
        <span class="gwt-CheckBox" style="display: block;">
        <span class="gwt-CheckBox" style="display: block;">
    <div class="gwt-Label matchruleheader">Name flags</div>
        <span class="gwt-CheckBox" style="display: block;">
        <span class="gwt-CheckBox" style="display: block;">
    <div class="gwt-Label matchruleheader">Other flags</div>
    <span class="gwt-CheckBox" style="display: block;">
    <span class="gwt-CheckBox" style="display: block;">
        <input id="gwt-uid-512" type="checkbox" value="on" tabindex="0" checked=""/>
        <label for="gwt-uid-512">Use alias list to get variations</label>
    </span>
    <span class="gwt-CheckBox" style="display: block;">
        <input id="gwt-uid-513" type="checkbox" value="on" tabindex="0" checked=""/>
        <label for="gwt-uid-513">Use ocr variations</label>
    </span>
</div>

note: input id for the checkbox is a dynamic value. I cannot use that one. input id="gwt-uid-513" Thanks, Riaz

1 Answer 1

1

ancestor is for parent/grant parent elements. As the 'input' elemet you are looking for in the same level, you can use preceding.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I have got it now using preceding.
//div[@id="match_configuration_edit_match_tab_data_objects_fp_flags"]//label[contains(text(), "Use alias list to get variations")]/preceding::input[1]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.