override click to scroll higher

19 views
Skip to first unread message

Tommy Marks

unread,
Apr 19, 2020, 8:33:17 PM4/19/20
to Geb User Mailing List
The website I test just changed so the header is static and the body scrolls under the top menu. (example: https://bertram.d.pr/KKWrUQ)
When geb tries to click an element under the header, it fails with error "org.openqa.selenium.ElementClickInterceptedException"

If I perform this before the click, it works fine:
interact { moveToElement(element) }
 //move to element i assume the same way selenium does before click
browser.driver.executeScript("javascript:window.scrollBy(0,-180);") //scroll up 180 pixels (height of top menu)

I'm thinking of overriding the DefaultNavigator click method to either scroll up a lot at the start, or catch the error, scroll up 180px and try again.
I found this thread on it, but NonEmptyNavigator is no longer used.

Any tips on how to override the click() method?
Would this be better implemented using NavigatorEventListenerSupport beforeClick()?

Thanks!

Marcin Erdmann

unread,
Apr 23, 2020, 3:53:31 PM4/23/20
to geb-...@googlegroups.com
Hi Tommy,

To answer your first question - you no longer need NonEmptyNavigator, simply return an instance of your custom navigator class (say it's called DefaultNavigatorWithOverridenClick) from innerNavigatorFactory in GebConfig:

innerNavigatorFactory = { Browser browser, Iterable<WebElement> elements ->
    new DefaultNavigatorWithOverridenClick(browser, elements)
}

To answer your second question - I'm not sure if this would be better implemented using a NavigatorEventListener but it's definitely possible to do it that way. I would say that both ways will do the job just fine with using the listener being maybe slightly more flexible but for your case it does not matter at all.

Cheers,
Marcin

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/93277ec1-e0d9-4d59-bf93-bb8d66474883%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages