我有以下XPATH,它使用了跟随兄弟的轴
可以转换为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?
我的Selenium 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>
谢谢Riaz
答案 0 :(得分: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]