2015-10-06 45 views
1

我有一个包含复选框列表的页面。我想单击具有指定文本的复选框。 例如我想单击具有名称“使用ocr变体”的复选框。 在HTML中,复选框位于Label标签上方。 在Firebug我可以找到以下XPath的标签标签:Selenium Webdriver XPATH我可以找到包含某些文本的标签,但无法获取标签标签上方的输入标签复选框

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

我想去1以上,其具有的复选框输入标签。 我曾尝试使用祖先,但不起作用

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

什么是我可以用得到的复选框的XPath或CSS?

的HTML是:

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

注:为复选框输入ID是一个动态值。我不能使用那个。 input id =“gwt-uid-513” 谢谢, Riaz

回答

1

祖先是父母/授予父母的元素。作为您正在寻找的“输入”元素,您可以使用preceding

+0

谢谢,我现在已经使用了前面的内容。 –

+0

// div [@ id =“match_configuration_edit_matit_match_tab_data_objects_fp_flags”] // label [contains(text(),“使用别名列表来获取变体”)] /在前:: input [1] –

+0

@RiazLadhani,很高兴它为你工作。 – vins

相关问题