Search code examples
selenium-webdriverrobotframeworkkeyword

Robot Framework with Selenium - Click Element is not working


I'm having issues with the Click Element keyword (SeleniumLibrary) with RFWK. It's not working consistently and I cannot find the root cause of it.
The page element looks like this:

<div class="grid-nav-controls">
  <span class="grid-nav-link" page-index="1">1</span>
  <span class="grid-nav-separator">| 
  </span><span class="grid-nav-link" page-index="2">2</span>
  <span class="grid-nav-separator">|</span>
  <div class="grid-nav-current-page">3</div>
  <span class="grid-nav-separator">|</span>
  <span class="grid-nav-link" page-index="4">4</span>
</div>

I want to access span with attribute page-index='4' or text()='4' (In application those are "buttons")

I tried (after checking if the page contains the element, it is enabled and visible) scrolling to this element (which works) and then:

Wait Until Keyword Succeeds  ${interval}  ${timeout}  Click Element ${locator}
Click Element  ${locator}
Click Element  ${locator}  action_chain=True
Click Element at Coordinates  ${locator}  0  0

I even wrote my own function using action chains:

@keyword("Perform Click Element")
def perform_click_element(self, element):
    self.driver = self.get_webdriver_instance()
    action = ActionChains(self.driver)
    try:
        action.move_to_element(element).click().perform()
    except Exception as e:
        logger.error(e)

And nothing works, locators I used:

${locator}  //span[text()='4']
${locator}  //span[@page-index='4']

It's not the first time I've had issues with clicking elements but changing locators worked in most cases. The worst thing is that in the log Keyword is passed and no errors are found in every tried case. Has anyone had a similar issue? Where to look for answers/how to debug this kind of problem?


Solution

  • Ok so after a long time debugging, checking and other various experiments it came down to version mismatch.

    Before running the scripts I have updated robotframework to the newest version, (which also updated robotframework-selenium library) but I left old version of selenium (3.141). Needed to only update the version!