[英]Selenium/Python - How to click on a button that appears only when cursor is hovering over it?
Basically on the UI there is a button that only becomes visible when hovered upon.基本上在 UI 上有一个按钮,只有在悬停时才可见。 I need to be able to click the Delete button when it's visible.我需要能够在它可见时单击删除按钮。 Would be ideal if there was some way I can check that I am hovering the right thing by checking against the words Edit Test Contract 1: uib-tooltip="Edit Test Contract 1">
如果有某种方法可以通过检查uib-tooltip="Edit Test Contract 1">
来检查我是否在正确的事情上悬停,那将是理想的: uib-tooltip="Edit Test Contract 1">
Html code: html代码:
<div class="ibox-content no-margins ">
<span tooltip-class="beacon-uib-tooltip" tooltip-append-to-body="true" uib-tooltip="Edit Test Contract 1">
<button class="name btn-link ng-binding ng-isolate-scope" ng-disabled="disableEdit()" mit-mini-modal="" ng-click="editContract(contract)">Test Contract 1</button>
</span>
<span class="icon-container hide-when-dragging">
<div class="show-when-hovering">
<span class="fa fa-times delete-icon ng-isolate-scope" uib-tooltip="Delete" tooltip-append-to-body="true" mit-mini-modal="" ng-click="deleteContract()"></span>
The python code I have atm returns nothing for some reason despite me searching for the right css, ng-click="deleteContract()"
.尽管我在寻找正确的 css ng-click="deleteContract()"
,但我在 atm 上的 python 代码由于某种原因没有返回任何内容。 The method by which I am attempting to click on the delete button is delete_contract()
.我试图点击删除按钮的方法是delete_contract()
。 Please let me know if you require any more information, I've tried to be as detailed as possible.如果您需要更多信息,请告诉我,我已尝试尽可能详细。
class Locator:
def __init__(self, selenium_context, short_wait_time_sec):
self.selenium_context = selenium_context
self.short_wait_time_sec = short_wait_time_sec
def find_elements_css(self, cssSelector):
return self.selenium_context.find_elements_by_css_selector(cssSelector)
def delete_contract(self, contract_name):
self.contract_list = self.page_loc.find_elements_css('button[ng-click="deleteContract()"]')
for contract in self.contract_list:
if contract.text == contract_name:
contract.click()
break
You can use ActionChains
to simulate hover您可以使用ActionChains
来模拟悬停
def delete_contract(self, contract_name):
action = ActionChains(selenium_context) # create ActionChains object
contract = page_loc.find_element_by_css_selector('span[ng-click="deleteContract()"]')
action.move_to_element(contract).perform() # move the mouse to the element
contract.click()
The delete button is in <span>
tag, not <button>
tag.删除按钮在<span>
标签中,而不是<button>
标签中。 The cssSelctor
should be 'span[ng-click="deleteContract()"]'
cssSelctor
应该是'span[ng-click="deleteContract()"]'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.