3

I've used a tool called Ranorex for my test automation projects, and it has an annoying issue with click actions: They are not stable. A click on any element can be missed at any time, even when the element was loaded seconds ago and there's nothing on top of it.

As I'm getting more and more tired of seeing clicks being missed for no reason, I'd like to find another tool that can surpass this issue. And of course the first one I think of is Selenium, due to a noticeable difference: Ranorex uses real mouse pointer to simulate mouse actions, while Selenium doesn't.

I've worked with Selenium before, but I think I don't have enough experience to make an assessment of the success rate of "click" actions with Selenium. So I'd love to know about your opinions on this matter, like how good (in general) Selenium handles click actions in your opinion, how often you see Selenium misses a click, how often you have to find another way to click an element... Thank you very much.

3

First of all, we need to understand the root cause of the click failure.

There can be several reasons for that:

  • Element is not loaded into the DOM at the moment of click action
  • Element is not visible on the page at the moment of click action
  • Click event is triggered on the other element that is mapped in the page object. E.g. you want to click on the checkbox that is represented as but the event handler is triggered on the element nearby. The click event is triggered only via the mouse click (e.g. onmouseclick JavaScript event) due to the specific SUT front-end implementation.

And many more options. So in case, you are aware of these issues and correctly manage them (via your test framework), there should not be any problems. Waits are usually handled on the framework level via proxy methods and injecting them in the most brittle places.

As an inspirational example:

  • See the implementation of Protractor framework and how it handles the AJAX/Angular testability
  • Selenide framework and it's waits
  • Many more examples of TAF that can be found on GitHub

Click method for web element itself is usually also customized/overridden with a combination of custom waits that would ensure that element is "clickable" (which is also a question to discuss, since there is no clear definition/standard for that condition) on the test automation framework level, so you can use the:

  • Default Selenium IWebelement.Click() implementation
  • Mouse click via Selenium Action builder API
  • JavaScript click by using the Selenium JavaScript executor, e.g.

Browser.InvokeScript("arguments[0].click();", _webElement);

From my experience - following these rules give you 99% stability and robustness of click events.

  • Thank you very much for your detailed explanation. According to your opinion, a correct wait determines the result of a click. In my past projects, I carefully implemented wait conditions yet click missing still happened, so I guess the click actions were the faulty ones (the wait conditions sucessfully waited for the elements to be visible and enabled, and the mouse pointed correctly at them). – Quang Huy Nguyễn Aug 27 at 17:11
2

My experience over the years has been pretty good with Selenium and clicks. Although IE has some quircks where a click focusses an element instead, but does not fire the click action. Double clicking these elements helps ;-)

Recently I had a element that didnt recieve its click randomly. So I build a method just for this element, but it was a first and also in a product we integrate with. If it was in our product I would see with the developers if we could make the events more stable.

public IWebElement UntilClicksResultsInNewElement(By byToClick, By byToFind, int milliseconds = 30000)

Works something like this:

  • Find byToClick element
  • Sets focus on byToClick
  • Click byToClick element
  • wait 1s for byToFind element to appear
  • Loops until byToFind element is visible
  • Thank you very much for all the information you provided, especially the one related to IE browser. Thanks to your answer, I can assume that Selenium can perform click actions much better than the tool I'm using, since you've had to use the above method for only one element so far. – Quang Huy Nguyễn Aug 26 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.