Add retry logic when "WebDriverException: Element is not clickable at point" ?

102 views
Skip to first unread message

ntotomanov

unread,
Apr 29, 2016, 7:01:40 PM4/29/16
to Geb Development Mailing List
Hello,

From time to time out tests fail with "Element is not clickable at point" because of timing issues - for example an overlay is still blocking the visibility of an element.
I was thinking about adding a method or overwriting the geb.navigator.NonEmptyNavigator.click() method with a retry logic which to handle such case.

I tried overwriting the method through the metaclass but it turns out that it is initialized already at that point. "Already initialized, cannot add new method:"

Can you give me some directions in which I can start working this out ?

Regards,
Nikki



Michael Kaiser

unread,
May 2, 2016, 2:27:40 PM5/2/16
to Geb Development Mailing List
We extended the click() method of geb.navigator.Neavigator like this:

import geb.Page
import geb.navigator.Navigator

abstract class BasePage extends Page implements AngularJsAware{

static def baseurl = "http://localhost:9090"

/***
* Extend Navigator.click() with waitFor { angularReady }
* angularReady is set by /src/main/webapp/angular-test-support.js
*/
BasePage() {
def oldExpand = Navigator.metaClass.getMetaMethod('click', null)

Navigator.metaClass.click = { ->
try {
oldExpand.invoke(delegate)
}
finally {
waitFor { angularReady }
}
}
}
}

this should work for you as well.

Regards,
Michael

ntotomanov

unread,
May 3, 2016, 5:00:05 PM5/3/16
to Geb Development Mailing List
Using this approach I was able to overwrite only EmptyNavigator but not the one which I wanted - NonEmptyNavigator. Here is my code:
Not sure why one gets overwritten but not the other one.

Enter code here...
AbstractPage() {

  println
"before meta overwrite "
  def oldExpand = Navigator.metaClass.getMetaMethod('click', null)
 
Navigator.metaClass.click = { ->

   
Exception ee;
   
for (int i = 0; i < 3; i++) {
     
try {
        println
("test click123")
       
return (Navigator) oldExpand.invoke(delegate)
     
} catch (e) {
        ee
= e
        println
("sleep 3")
       
TimeUnit.SECONDS.sleep(3)
       
throw e
     
}
   
}
   
throw ee
 
}
}

ntotomanov

unread,
May 4, 2016, 5:38:51 AM5/4/16
to Geb Development Mailing List
I will try to just patch the version of Geb with this new method ... :)
Was not able to make NonEmptyNavigator use the click version I was overwriting

Marcin Erdmann

unread,
May 5, 2016, 5:53:26 PM5/5/16
to geb...@googlegroups.com
There's no need to resort to monkey patching here as Geb provides a mechanism for using a custom Navigator implementation: http://www.gebish.org/manual/current/#navigator-factory

All you need to do is to create a custom navigator implementation that extends NonEmptyNavigator and overrides the click() method and then register a navigator factory via the configuration which returns instances of that custom navigator implementation.

--
You received this message because you are subscribed to the Google Groups "Geb Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-dev+u...@googlegroups.com.
To post to this group, send email to geb...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-dev/defe649e-9ebd-406c-9100-d8bc8b3aaddf%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

ntotomanov

unread,
May 6, 2016, 3:46:44 AM5/6/16
to Geb Development Mailing List
Beautiful!!! Geb is really incredible tool!
Reply all
Reply to author
Forward
0 new messages