简体   繁体   English

Selenium/Python - 如何单击仅在光标悬停在其上时才出现的按钮?

[英]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.

相关问题 如何在 select 一个特定元素时它只出现在你 hover 你的鼠标悬停它的时候? Selenium webdriver python; - How to select a specific element when it only appears when you hover your mouse over it? Selenium webdriver python; Python selenium 点击按钮,如果它出现在屏幕上 - Python selenium click on button if it appears on screen 仅当光标悬停在标签上时,如何将光标更改为手形? - How do I change my cursor to a hand ONLY when it is hovering over a Label? 在 Python 中用鼠标光标悬停在某物上时显示消息 - Display message when hovering over something with mouse cursor in Python 单击另一个带有 Python Selenium 的按钮后出现的单击子元素按钮? - Click sub-element button when it appears after clicking another button with Python Selenium? 将光标悬停在画布上时如何显示画布坐标? - How to display canvas coordinates when hovering cursor over canvas? 在Selenium(Python)中-如何仅在上传文件后单击按钮? - In Selenium (Python) - how to click a button _only after_ a file is uploaded? Selenium 脚本来检测按钮的存在并在它看起来不起作用时单击它 - Selenium script to detect presence of button and to click on it when it appears not working 如何在 Python 中单击带有 selenium 的按钮 - How to click on button with selenium in Python 如何在python selenium中单击按钮? - how to click button in python selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM