1

Basically on the UI there is a button that only becomes visible when hovered upon. 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">

Html code:

<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()". The method by which I am attempting to click on the delete button is 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

1 Answer 1

3

You can use ActionChains to simulate hover

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. The cssSelctor should be 'span[ng-click="deleteContract()"]'

Sign up to request clarification or add additional context in comments.

10 Comments

Only problem with this is that the field contract_name is Test Contract 1 and that self.contract_list returns [] despite searching for the right code, any ideas as to what your 3rd line of code of your answer might be doing wrong? Also do you have any idea how I can get it to check for the correct contract_name based on the html code above, should I be searching for a class first?
@user4659009 I edited my answer. The text Test Contract 1 belongs to another element and the delete button doesn't have text. You can't compare them.
that makes sense, I've tried your edited answer, it fails on the 2nd last line of your code with the following error message: File "/Users/ss/anaconda/envs/web/lib/python3.4/site-packages/selenium/webdriver/common/action_chains.py", line 72, in perform action() File "/Users/ss/anaconda/envs/web/lib/python3.4/site-packages/selenium/webdriver/common/action_chains.py", line 217, in <lambda> self._driver.execute(Command.MOVE_TO, {'element': to_element.id})) AttributeError: 'WebElement' object has no attribute 'execute'
@user4659009 Try page_loc.find_element_by_css_selector('span[ng-click="deleteContract()"]')
contract returns back the following, not sure if this is helpful in seeing what could be causing the problem or not? - <selenium.webdriver.remote.webelement.WebElement (session="c481cda6-ed6e-2949-ae43-7db74c5ea9f6", element="{a251e594-671d-b344-a750-4877b121c554}")>
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.