Riaz Ladhani
Riaz Ladhani

Reputation: 4062

Selenium Webdriver XPATH I can find the label which contains certain text but I cannot get the Input tag checkbox above the Label tag

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

Upvotes: 1

Views: 1360

Answers (1)

vins
vins

Reputation: 15370

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

Upvotes: 1

Related Questions