【发布时间】:2019-08-02 01:47:22
【问题描述】:
在声明文本后,我需要单击 HTML 表中的复选框。下面是html。
<div class="k-widget k-grid ">
<div class="k-grid-header" style="padding: 0px 16px 0px 0px;">
<div class="k-grid-header-wrap">
<table>
<colgroup>
<col width="50px">
<col>
<col>
</colgroup>
<thead>
<tr>
<th aria-sort="" colspan="1" rowspan="1" class="k-header checkbox-grid-column"><input id="c3c07f7e-5119-4a36-9f67-98fa4d21fa07" type="checkbox" class="k-checkbox"><label class="k-checkbox-label" for="c3c07f7e-5119-4a36-9f67-98fa4d21fa07"></label></th>
<th aria-sort="" colspan="1" rowspan="1" class="k-header"><a class="k-link">Permission</a></th>
<th aria-sort="" colspan="1" rowspan="1" class="k-header"><a class="k-link">Description</a></th>
</tr>
</thead>
</table>
</div>
</div>
<div class="k-grid-container">
<div class="k-grid-content k-virtual-content">
<div style="position: relative;">
<table tabindex="-1" class="k-grid-table">
<colgroup>
<col width="50px">
<col>
<col>
</colgroup>
<tbody>
<tr class="k-master-row">
<td colspan="1" class="checkbox-grid-column"><input id="c8711bab-702a-43b9-8a75-02ad06a8baa3" type="checkbox" class="k-checkbox"><label class="k-checkbox-label" for="c8711bab-702a-43b9-8a75-02ad06a8baa3"></label></td>
<td>ACCESSGROUP_BULKDELETE</td>
<td colspan="1">Enable Bulk Delete button in access group management</td>
</tr>
<tr class="k-master-row k-alt">
<td colspan="1" class="checkbox-grid-column"><input id="a029bc1e-53d8-4328-89ce-6640363d515a" type="checkbox" class="k-checkbox"><label class="k-checkbox-label" for="a029bc1e-53d8-4328-89ce-6640363d515a"></label></td>
<td>ACCESSGROUP_DELETE</td>
<td colspan="1">Enable Delete Button in the access group details page</td>
</tr>
<tr class="k-master-row">
<td colspan="1" class="checkbox-grid-column"><input id="645f8474-9840-48e2-a02c-112178aaf5e2" type="checkbox" class="k-checkbox"><label class="k-checkbox-label" for="645f8474-9840-48e2-a02c-112178aaf5e2"></label></td>
<td>ACCESSGROUP_NEW</td>
我能够使用提到的代码从 TR 中获取文本
table_id = context.driver.find_elements(By.XPATH, '//*[@id="root"]//table//tbody//tr//td[1]')
print (table_id)
# get all of the rows in the table
#rows = table_id.find_elements(By.TAG_NAME, "tr")
#for row in rows:
#permission = row.find_elements(By.TAG_NAME, 'td')[1]
#print (permission.text)
但我需要遍历并找到确切的文本,然后单击复选框。
【问题讨论】:
-
您在寻找什么文字?你想点击哪个
INPUT?
标签: python selenium selenium-webdriver xpath webdriverwait