2016-10-06 22 views
0

我有以下XPath和它使用的軸以下同胞硒XPATH HTML表格輸入fieldwith以下同胞可以將其轉換爲CSS

這能轉換爲CSS? CSS比XPATH更快。如果我可以將它轉換爲CSS來進行我的Selenium測試,那將會很好。

XPATH://table[@id="data_configuration_edit_data_object_tab_details_tb_fields"]//td/div/input[@value="AREACODE"]/../../following-sibling::td[2]/div/input

什麼是CSS嗎?

我的硒Python代碼是:

def enter_size_in_size_field(self, name, value): 
    # Params name : The name of the user defined field e.g. AREACODE 
    # Params value : Size value for the string size field e.g. 30, 50 
    size_element_xpath = '//table[@id="data_configuration_edit_data_object_tab_details_tb_fields"]//td/di v/input[@value="%s"]/../../following-sibling::td[2]/div/input' % name 
    size_element = self.get_element(By.XPATH, size_element_xpath) 

的HTML片段是:

<table id="data_configuration_edit_data_object_tab_details_tb_fields" class="GFNQNVHJE border" cellspacing="0" __gwtcellbasedwidgetimpldispatchingfocus="true" __gwtcellbasedwidgetimpldispatchingblur="true"> 
    <thead aria-hidden="false"> 
     <colgroup> 
      <tbody style=""> 
       <tr class="GFNQNVHCD GFNQNVHJD" __gwt_subrow="0" __gwt_row="0"> 
        <td class="GFNQNVHBD GFNQNVHDD GFNQNVHED GFNQNVHKD"> 
         <div __gwt_cell="cell-gwt-uid-262" style="outline-style:none;"> 
          <input type="checkbox" tabindex="-1"/> 
         </div> 
        </td> 
        <td class="GFNQNVHBD GFNQNVHDD GFNQNVHKD"> 
         <div __gwt_cell="cell-gwt-uid-263" style="outline-style:none;"> 
          <input id="" type="text" style="color: black;" value="AREACODE"/> 
         </div> 
        </td> 
        <td class="GFNQNVHBD GFNQNVHDD GFNQNVHKD"> 
         <div __gwt_cell="cell-gwt-uid-264" style="outline-style:none;"> 
          <select tabindex="-1"> 
           <option value="Integer">Integer</option> 
           <option selected="selected" value="Text string">Text string</option> 
           <option value="Date/time">Date/time</option> 
           <option value="Floating point">Floating point</option> 
          </select> 
         </div> 
        </td> 
        <td class="GFNQNVHBD GFNQNVHDD GFNQNVHOD GFNQNVHKD"> 
         <div __gwt_cell="cell-gwt-uid-265" style="outline-style:none;"> 
          <input id="" type="text" style="color: black;" value="30"/> 
         </div> 
        </td> 
       </tr> 
       <tr class="GFNQNVHCE" __gwt_subrow="0" __gwt_row="1"> 
       </tbody> 
       <tbody style="display: none;"> 
        <tfoot style="display: none;" aria-hidden="true"/> 
</table> 

感謝,里亞茲

+0

你有沒有嘗試firefox的firebug插件可以幫助做同樣的事情? – Rao

回答

0

是的,這是可以將上述的XPath轉換爲CSS,嘗試下面的代碼,

table[id='data_configuration_edit_data_object_tab_details_tb_fields'] input[value='%s'] td:nth-child(2) > div > input[value=name] 
+0

它不適合我。如果我只使用table [id =「data_configuration_edit_data_object_tab_details_tb_fields」]輸入[value =「AREACODE」],它將工作並找到AREACODE字段。找到輸入[value = name]的部分不起作用 –