该表的完整HTML代码如下:
<table id="clearablecombo-1497" class="x-field clearableCombo x-form-item x-field-default x-anchor-form-item" cellpadding="0" style="table-layout: fixed; width: 287px;">
<tbody>
<tr id="clearablecombo-1497-inputRow">
<td id="clearablecombo-1497-labelCell" class="x-field-label-cell" width="105" valign="top" halign="right" style="">
<label id="clearablecombo-1497-labelEl" class="x-form-item-label x-form-item-label-right" style="width:100px;margin-right:5px;" for="clearablecombo-1497-inputEl">Document Status:</label>
</td>
<td id="clearablecombo-1497-bodyEl" class="x-form-item-body x-form-trigger-wrap-focus" colspan="2" role="presentation" style="width: 100%;">
<table id="clearablecombo-1497-triggerWrap" class="x-form-trigger-wrap" cellspacing="0" cellpadding="0" style="width: 100%; table-layout: fixed;">
<tbody>
<tr>
<td id="clearablecombo-1497-inputCell" class="x-form-trigger-input-cell" style="width: 100%;">
<div id="ext-gen1890" class="x-hide-display x-form-data-hidden" role="presentation"/>
<input id="clearablecombo-1497-inputEl" class="x-form-field x-form-text x-form-focus x-field-form-focus x-field-default-form-focus" type="text" style="width: 100%; text-transform: uppercase; -moz-user-select: text;" name="documentStatus" autocomplete="off" aria-invalid="false"/>
</td>
<td id="ext-gen1888" class="x-trigger-cell" valign="top" style="width:26px">
<div id="ext-gen1886" class="x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-unselectable x-form-trigger-over x-form-arrow-trigger-over" role="button" style="-moz-user-select: none;"/>
</td>
<td id="ext-gen1889" class="x-trigger-cell" valign="top" style="width:26px">
<div id="ext-gen1887" class="x-trigger-index-1 x-form-trigger x-form-clear-trigger x-form-trigger-last x-unselectable" role="button" style="-moz-user-select: none;"/>
</td>
</tr>
</tbody>
</table>
</td>
<td id="clearablecombo-1497-errorEl" class="x-form-error-msg x-external-error-icon x-form-invalid-icon" width="0" style="display:none" data-errorqtip=""/>
</tr>
</tbody>
</table>
<div id="ext-gen1886" class="x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-unselectable x-form-trigger-over x-form-arrow-trigger-over" role="button" style="-moz-user-select: none;"/>
<div id="boundlist-1558" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default" tabindex="-1" style="left: 136px; top: 346px; height: auto; z-index: 19001; width: 182px;">
<div id="boundlist-1558-listEl" class="x-boundlist-list-ct" style="overflow: auto; height: auto;">
<ul>
<li class="x-boundlist-item x-boundlist-item-over" role="option">All</li>
<li class="x-boundlist-item" role="option">Waiting QA</li>
<li class="x-boundlist-item" role="option">AutoTec Approved</li>
<li class="x-boundlist-item" role="option">User Approved</li>
<li class="x-boundlist-item" role="option">Rejected</li>
<li class="x-boundlist-item" role="option">Deleted</li>
</ul>
</div>
</div>
答案 0 :(得分:0)
据我所知,这些是目标要素:
xpath = '//div[contains(id, "ext-gen")][@class="x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-unselectable x-form-trigger-over x-form-arrow-trigger-over"]'
drop_down = self.driver.find_element_by_xpath(xpath)
drop_down.click()
xpath = '//li[@class="x-boundlist-item"][contains(text(), "Rejected")]'
option = self.driver.find_element_by_xpath(xpath)
option.click()
答案 1 :(得分:0)
我认为&#39;角色&#39;在这种情况下,找到元素是最好的attr:
--this one select your desired element
"//div[contains(id, 'ext-gen')][@role='button'][contains(@class, 'x-form-trigger-over')]"
--this one select your desired option
"//li[@role='option'][text()='Rejected']"