gpt4 book ai didi

ruby - 选中表格中的复选框

转载 作者:数据小太阳 更新时间:2023-10-29 09:02:10 28 4
gpt4 key购买 nike

在我的应用程序中,我选中了任一复选框并单击保存按钮。我使用 with table 如下选择选项,但它不起作用:

# with in table, set 
within_table('countryTable') do
find(:xpath, "//tbody/tr/td[1]/checkbox").set(true)
end

click_button('Save')

但它不起作用......

为此所有者选择国家

                                                <tr>
<td class='first'>
<input type='checkbox' id='CheckboxAU' name='AU' value='AU' />
</td>
<td>
Australia
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxCA' name='CA' value='CA' />
</td>
<td>
Canada
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxFR' name='FR' value='FR' />
</td>
<td>
France
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxGG' name='GG' value='GG' />
</td>
<td>
Guernsey
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxJP' name='JP' value='JP' />
</td>
<td>
Japan
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxNZ' name='NZ' value='NZ' />
</td>
<td>
New Zealand
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxZA' name='ZA' value='ZA' />
</td>
<td>
South Africa
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxCH' name='CH' value='CH' />
</td>
<td>
Switzerland
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxAE' name='AE' value='AE' />
</td>
<td>
United Arab Emirates
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxGB' name='GB' value='GB' />
</td>
<td>
United Kingdom
</td>
</tr>

<tr>
<td class='first'>
<input type='checkbox' id='CheckboxUS' name='US' value='US' />
</td>
<td>
United States
</td>
</tr>

</tbody>
</table>
</div>
</td>
</tr>
</table>

最佳答案

您可以通过 id、css 或 xpath 到达复选框。

# to check the FR with xpath
find(:xpath, "//input[@name='FR']").click()

# to check the FR with id
find(:id, "CheckboxFR").click()

# to check the FR with css
find(:css, "#CheckboxFR").click()

如果你想使用within_table来缩小范围:

within_table(find(:id, "table_id")) do 
find(:id, "id_of_option").click()
end

关于ruby - 选中表格中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33010887/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com