DEV Community

Danny Perez
Danny Perez

Posted on • Originally published at intricatecloud.io

webdriverIO tips: element wrapped in a div is not clickable

Have you run into an error saying "Element is not clickable at point" when you're trying to click a button? You might be seeing this if you have a spinner that appears on your buttons or its a customized button (like a div as a button with inner styled elements). In these cases, you're kinda out of luck if you want selenium to be able to do it because it can't see the element that you want to click on. However... you can hack around it. While selenium isn't able to click the button obscured by another element, the browser can still do it and selenium can inject javascript to run inside the browser. Check out this example:

var runInBrowser = function(argument) { 
  argument.click();
};
var elementToClickOn = browser.$(selector)
> browser.execute(runInBrowser, elementToClickOn);
Enter fullscreen mode Exit fullscreen mode

.execute to the rescue here. You can inject a snippet into the page, so as long as the browser can do it, you can get past the "Element is not clickable" error. This is a hack though and you should only use it sparingly when you need it, $(element).click() should still work the majority of the time. Check out this Stack Overflow discussion here if you're in this situation


Last week, I started working on integrating a test suite previously built using Nightwatch, and making it work with webdriverIO. While I love all of webdriverIO’s features like synchronous code when using their test runner and a REPL, there were a few things that I’d like to share which were a little hard to find in the docs or on a quick search.

In case you missed it... Each day this week, I've been posting one thing I've learned while setting up webdriverIO. Check out my previous posts here:

Top comments (2)

Collapse
 
vuminhkhoi1802 profile image
Kevin Vu

Thanks, mate. You're such a life saver. I've been stuck with the elements that are not clickable by Selenium standard. This is such a neat workaround.

Collapse
 
intricatecloud profile image
Danny Perez

Glad you found it helpful!