代码段
def get_all_rows_approval():
approval_table = driver.find_element(By.XPATH, '//*[@id="change_request.sysapproval_approver.sysapproval_table"]/tbody')
rows = approval_table.find_elements(By.XPATH, "//*[contains(@id,'row_change_request.sysapproval_approver.sysapproval')]")
for row in rows:
col = row.find_element(By.XPATH, '//a[contains(text() , "Luke Wilson")]')
menu = col.find_element_by_class_name("context_menu")
actions = ActionChains(menu)
actions.move_to_element(menu)
actions.click(menu)
actions.perform()
<tbody class="list2_body">
<tr id="row_change_request.sysapproval_approver.sysapproval_30f168b2dbeb5300b58ad360cf961998" class="list_row list_odd" style="" sys_id="30f168b2dbeb5300b58ad360cf961998" record_class="sysapproval_approver" data-updated-on="2018-07-30 13:36:23" collapsed="true" data-type="list2_row" data-list_id="change_request.sysapproval_approver.sysapproval">
<td class="list_decoration_cell col-control col-small col-center " style="white-space:nowrap;" rowspan="1"><span class="input-group-checkbox"><input title="Mark record for List Action" id="check_change_request.sysapproval_approver.sysapproval_30f168b2dbeb5300b58ad360cf961998" name="check_change_request.sysapproval_approver.sysapproval" class="checkbox " data-type="list2_checkbox" data-list_id="change_request.sysapproval_approver.sysapproval" data-original-title="Mark record for List Action" type="checkbox"><label for="check_change_request.sysapproval_approver.sysapproval_30f168b2dbeb5300b58ad360cf961998" style="" class="checkbox-label"><span class="sr-only">Select record for action</span></label></span></td>
<td class="list_decoration_cell col-small col-center " rowspan="1"><a href="sysapproval_approver.do?sys_id=30f168b2dbeb5300b58ad360cf961998&sysparm_view=&sysparm_record_target=task_ci&sysparm_record_row=1&sysparm_record_list=sysapproval%3De6d1ac72dbeb5300b58ad360cf96193e%5EORDERBYorder&sysparm_record_rows=5" class="btn btn-icon table-btn-lg icon-info list_popup" data-type="list2_popup" data-list_id="change_request.sysapproval_approver.sysapproval" style="margin-left:0px"><span class="sr-only">Preview</span></a></td>
<td class="vt" ng-non-bindable="">
<span class="sr-only"></span>
<div class="list2_cell_background" style="background-color: khaki"></div>
<a class="linked formlink" href="sysapproval_approver.do?sys_id=30f168b2dbeb5300b58ad360cf961998&sysparm_record_target=sysapproval_approver&sysparm_record_row=1&sysparm_record_rows=5&sysparm_record_list=sysapproval%3De6d1ac72dbeb5300b58ad360cf96193e%5EORDERBYorder">Requested</a>
</td>
<td class="vt" ng-non-bindable=""><a class="linked" sys_id="97000fcc0a0a0a6e0104ca999f619e5b" href="sys_user.do?sys_id=97000fcc0a0a0a6e0104ca999f619e5b">Christen Mitchell</a></td>
<td class="vt" ng-non-bindable=""><a class="linked" sys_id="b85d44954a3623120004689b2d5dd60a" href="sys_user_group.do?sys_id=b85d44954a3623120004689b2d5dd60a">CAB Approval</a></td>
<td class="vt" ng-non-bindable=""></td>
<td class="vt" ng-non-bindable="">
<div class="datex date-calendar" title="" timeago="2018-07-30 13:36:23" timeago-attrs="title" data-original-title="5m ago">2018-07-30 06:36:23</div>
<div class="datex date-calendar-short" title="just now" timeago="2018-07-30 13:36:23" timeago-attrs="title" data-original-title="5m ago">07-30 06:36</div>
<div class="datex date-timeago" title="2018-07-30 06:36:23" timeago="2018-07-30 13:36:23" data-original-title="2018-07-30 06:36:23" null="5m ago">5m ago</div>
</td>
<td class="vt vt-spacer" style="padding: 0"></td>
</tr>
<tr id="row_change_request.sysapproval_approver.sysapproval_34f168b2dbeb5300b58ad360cf961997" class="list_row list_even" style="" sys_id="34f168b2dbeb5300b58ad360cf961997" record_class="sysapproval_approver" data-updated-on="2018-07-30 13:36:23" collapsed="true" data-type="list2_row" data-list_id="change_request.sysapproval_approver.sysapproval">
<td class="list_decoration_cell col-control col-small col-center " style="white-space:nowrap;" rowspan="1"><span class="input-group-checkbox"><input title="Mark record for List Action" id="check_change_request.sysapproval_approver.sysapproval_34f168b2dbeb5300b58ad360cf961997" name="check_change_request.sysapproval_approver.sysapproval" class="checkbox " data-type="list2_checkbox" data-list_id="change_request.sysapproval_approver.sysapproval" data-original-title="Mark record for List Action" type="checkbox"><label for="check_change_request.sysapproval_approver.sysapproval_34f168b2dbeb5300b58ad360cf961997" style="" class="checkbox-label"><span class="sr-only">Select record for action</span></label></span></td>
<td class="list_decoration_cell col-small col-center " rowspan="1"><a href="sysapproval_approver.do?sys_id=34f168b2dbeb5300b58ad360cf961997&sysparm_view=&sysparm_record_target=sysapproval_approver&sysparm_record_row=2&sysparm_record_list=sysapproval%3De6d1ac72dbeb5300b58ad360cf96193e%5EORDERBYorder&sysparm_record_rows=5" class="btn btn-icon table-btn-lg icon-info list_popup" data-type="list2_popup" data-list_id="change_request.sysapproval_approver.sysapproval" style="margin-left:0px"><span class="sr-only">Preview</span></a></td>
<td class="vt" ng-non-bindable="">
<span class="sr-only"></span>
<div class="list2_cell_background" style="background-color: khaki"></div>
<a class="linked formlink" href="sysapproval_approver.do?sys_id=34f168b2dbeb5300b58ad360cf961997&sysparm_record_target=sysapproval_approver&sysparm_record_row=2&sysparm_record_rows=5&sysparm_record_list=sysapproval%3De6d1ac72dbeb5300b58ad360cf96193e%5EORDERBYorder">Requested</a>
</td>
<td class="vt" ng-non-bindable=""><a class="linked" sys_id="46d96f57a9fe198101947a9620895886" href="sys_user.do?sys_id=46d96f57a9fe198101947a9620895886">Luke Wilson</a></td>
<td class="vt" ng-non-bindable=""><a class="linked" sys_id="b85d44954a3623120004689b2d5dd60a" href="sys_user_group.do?sys_id=b85d44954a3623120004689b2d5dd60a">CAB Approval</a></td>
<td class="vt" ng-non-bindable=""></td>
<td class="vt" ng-non-bindable="">
<div class="datex date-calendar" title="" timeago="2018-07-30 13:36:23" timeago-attrs="title" data-original-title="5m ago">2018-07-30 06:36:23</div>
<div class="datex date-calendar-short" title="just now" timeago="2018-07-30 13:36:23" timeago-attrs="title" data-original-title="5m ago">07-30 06:36</div>
<div class="datex date-timeago" title="2018-07-30 06:36:23" timeago="2018-07-30 13:36:23" data-original-title="2018-07-30 06:36:23" null="5m ago">5m ago</div>
</td>
<td class="vt vt-spacer" style="padding: 0"></td>
</tr>
<tr id="row_change_request.sysapproval_approver.sysapproval_b4f168b2dbeb5300b58ad360cf961998" class="list_row list_odd" style="" sys_id="b4f168b2dbeb5300b58ad360cf961998" record_class="sysapproval_approver" data-updated-on="2018-07-30 13:36:23" collapsed="true" data-type="list2_row" data-list_id="change_request.sysapproval_approver.sysapproval">
<td class="list_decoration_cell col-control col-small col-center " style="white-space:nowrap;" rowspan="1"><span class="input-group-checkbox"><input title="Mark record for List Action" id="check_change_request.sysapproval_approver.sysapproval_b4f168b2dbeb5300b58ad360cf961998" name="check_change_request.sysapproval_approver.sysapproval" class="checkbox " data-type="list2_checkbox" data-list_id="change_request.sysapproval_approver.sysapproval" data-original-title="Mark record for List Action" type="checkbox"><label for="check_change_request.sysapproval_approver.sysapproval_b4f168b2dbeb5300b58ad360cf961998" style="" class="checkbox-label"><span class="sr-only">Select record for action</span></label></span></td>
<td class="list_decoration_cell col-small col-center " rowspan="1"><a href="sysapproval_approver.do?sys_id=b4f168b2dbeb5300b58ad360cf961998&sysparm_view=&sysparm_record_target=sysapproval_approver&sysparm_record_row=3&sysparm_record_list=sysapproval%3De6d1ac72dbeb5300b58ad360cf96193e%5EORDERBYorder&sysparm_record_rows=5" class="btn btn-icon table-btn-lg icon-info list_popup" data-type="list2_popup" data-list_id="change_request.sysapproval_approver.sysapproval" style="margin-left:0px"><span class="sr-only">Preview</span></a></td>
<td class="vt" ng-non-bindable="">
<span class="sr-only"></span>
<div class="list2_cell_background" style="background-color: khaki"></div>
<a class="linked formlink" href="sysapproval_approver.do?sys_id=b4f168b2dbeb5300b58ad360cf961998&sysparm_record_target=sysapproval_approver&sysparm_record_row=3&sysparm_record_rows=5&sysparm_record_list=sysapproval%3De6d1ac72dbeb5300b58ad360cf96193e%5EORDERBYorder">Requested</a>
</td>
<td class="vt" ng-non-bindable=""><a class="linked" sys_id="ee826bf03710200044e0bfc8bcbe5de6" href="sys_user.do?sys_id=ee826bf03710200044e0bfc8bcbe5de6">Bernard Laboy</a></td>
<td class="vt" ng-non-bindable=""><a class="linked" sys_id="b85d44954a3623120004689b2d5dd60a" href="sys_user_group.do?sys_id=b85d44954a3623120004689b2d5dd60a">CAB Approval</a></td>
<td class="vt" ng-non-bindable=""></td>
<td class="vt" ng-non-bindable="">
<div class="datex date-calendar" title="" timeago="2018-07-30 13:36:23" timeago-attrs="title" data-original-title="5m ago">2018-07-30 06:36:23</div>
<div class="datex date-calendar-short" title="just now" timeago="2018-07-30 13:36:23" timeago-attrs="title" data-original-title="5m ago">07-30 06:36</div>
<div class="datex date-timeago" title="2018-07-30 06:36:23" timeago="2018-07-30 13:36:23" data-original-title="2018-07-30 06:36:23" null="5m ago">5m ago</div>
</td>
<td class="vt vt-spacer" style="padding: 0"></td>
</tr>
<tr id="row_change_request.sysapproval_approver.sysapproval_b8f168b2dbeb5300b58ad360cf961997" class="list_row list_even" style="" sys_id="b8f168b2dbeb5300b58ad360cf961997" record_class="sysapproval_approver" data-updated-on="2018-07-30 13:36:23" collapsed="true" data-type="list2_row" data-list_id="change_request.sysapproval_approver.sysapproval">
<td class="list_decoration_cell col-control col-small col-center " style="white-space:nowrap;" rowspan="1"><span class="input-group-checkbox"><input title="Mark record for List Action" id="check_change_request.sysapproval_approver.sysapproval_b8f168b2dbeb5300b58ad360cf961997" name="check_change_request.sysapproval_approver.sysapproval" class="checkbox " data-type="list2_checkbox" data-list_id="change_request.sysapproval_approver.sysapproval" data-original-title="Mark record for List Action" type="checkbox"><label for="check_change_request.sysapproval_approver.sysapproval_b8f168b2dbeb5300b58ad360cf961997" style="" class="checkbox-label"><span class="sr-only">Select record for action</span></label></span></td>
<td class="list_decoration_cell col-small col-center " rowspan="1"><a href="sysapproval_approver.do?sys_id=b8f168b2dbeb5300b58ad360cf961997&sysparm_view=&sysparm_record_target=sysapproval_approver&sysparm_record_row=4&sysparm_record_list=sysapproval%3De6d1ac72dbeb5300b58ad360cf96193e%5EORDERBYorder&sysparm_record_rows=5" class="btn btn-icon table-btn-lg icon-info list_popup" data-type="list2_popup" data-list_id="change_request.sysapproval_approver.sysapproval" style="margin-left:0px"><span class="sr-only">Preview</span></a></td>
<td class="vt" ng-non-bindable="">
<span class="sr-only"></span>
<div class="list2_cell_background" style="background-color: khaki"></div>
<a class="linked formlink" href="sysapproval_approver.do?sys_id=b8f168b2dbeb5300b58ad360cf961997&sysparm_record_target=sysapproval_approver&sysparm_record_row=4&sysparm_record_rows=5&sysparm_record_list=sysapproval%3De6d1ac72dbeb5300b58ad360cf96193e%5EORDERBYorder">Requested</a>
</td>
<td class="vt" ng-non-bindable=""><a class="linked" sys_id="62d78687c0a8010e00b3d84178adc913" href="sys_user.do?sys_id=62d78687c0a8010e00b3d84178adc913">Ron Kettering</a></td>
<td class="vt" ng-non-bindable=""><a class="linked" sys_id="b85d44954a3623120004689b2d5dd60a" href="sys_user_group.do?sys_id=b85d44954a3623120004689b2d5dd60a">CAB Approval</a></td>
<td class="vt" ng-non-bindable=""></td>
<td class="vt" ng-non-bindable="">
<div class="datex date-calendar" title="just now" timeago="2018-07-30 13:36:23" timeago-attrs="title" data-original-title="5m ago">2018-07-30 06:36:23</div>
<div class="datex date-calendar-short" title="just now" timeago="2018-07-30 13:36:23" timeago-attrs="title" data-original-title="5m ago">07-30 06:36</div>
<div class="datex date-timeago" title="2018-07-30 06:36:23" timeago="2018-07-30 13:36:23" data-original-title="2018-07-30 06:36:23" null="5m ago">5m ago</div>
</td>
<td class="vt vt-spacer" style="padding: 0"></td>
</tr>
</tbody>
</table>
<a id="change_request.sysapproval_approver.sysapproval_bottom" href="javascript:function(evt){if(evt){evt.stopPropagation();}}"><span class="sr-only">Bottom of table</span></a>
</div>
</td>
</tr>
</tbody>
</table>
</html>
注意,click()
不会执行右键单击,而是context_click()
如果您想根据名称右键单击,那么您可以使用以下代码:
ActionChains(driver).context_click(driver.find_element_by_xpath("//a[text()='Luke Wilson']").perform()
您也可以尝试使用以下方法:
action = ActionChains(driver)
action.move_to_element(driver.find_element_by_xpath("//a[text()='Luke Wilson']")).perform();
action.context_click().perform()
当用户在网页中点击鼠标右键后,会唤出一个菜单,在上面有复制、粘贴和翻译等选项,为用户提供快捷便利的功能。Chrome也将这里开放给了开发者,也就是说我们可以把自己所编写的扩展功能放到右键菜单中。 要将扩展加入到右键菜单中,首先要在Manifest的permissions域中声明contextMenus权限。 "permissions": [ "contextMenus" ] 同时还要在i
问题内容: 我想知道是否有最佳实践/正确的方法来为React组件设置右键菜单。 我目前有这个… 可以,但是感觉有点混乱,我想知道是否还有其他方法可以使用,任何信息将不胜感激, 谢谢! 问题答案: 更新: 想通了-这是您可以做的 在渲染中,您可以将函数传递给onContextMenu,以使该react组件发生右键单击。
问题内容: 右键单击Javascript事件吗?如果可以,该如何使用? 问题答案: 正如其他人提到的那样,可以[通过常规鼠标事件(mousedown,mouseup,click)检测[鼠标右键。但是,如果在弹出右键单击菜单时正在寻找触发事件,那么您所寻找的位置是错误的。也可以通过键盘(在Windows和某些Linux上为shift + F10或上下文菜单键)访问右键单击/上下文菜单。在这种情况下,
问题内容: 嗨,我正在搜索如何(仅)启用鼠标右键,并使用NetBeans在jFrame中显示一个弹出菜单。使用我的代码为: 我仍然无法获得最佳结果,因为它还会在单击鼠标左键时弹出,也向我暗示我正在做任何错误操作。 问题答案: 这就是它应该真正做到的事情,它很棒而且有用 别忘了添加一个导入 玩得开心…
问题内容: 我正在尝试使用selenium进行右键单击,对此有任何想法吗? 问题答案: 我已经尝试过ActionSequence,而且效果很好。 找不到ContextClick函数,应使用click。 因此,应如下所示: 元素是您的Web元素,2表示右键。 要大致模拟JavaScript中的右键单击,请查看JavaScript模拟代码中的右键单击。
问题内容: 在我的三个按钮上,鼠标=中键单击和=右键单击。 两键鼠标就是这种情况吗? 谢谢 问题答案: 为了避免任何歧义,请使用SwingUtilities中的实用程序方法: