Firefox scroll false positive

13 views
Skip to first unread message

M T

unread,
May 5, 2020, 6:11:21 AM5/5/20
to Geb User Mailing List
Hi

First of all let me just thank the Geb team. Great tool.

I am having an issue with scrolling with Firefox. I know geb should always scroll into view the elements that i want to interact with.
The same test with Chrome is passing.
I tried interact{moveToElement($"element"), same behaviour.

The wierdest part is that I'm not getting a "could not scroll into view" error. The test will fail only on the next step, as if it's interacting with the element correctly, but there is no interaction.
I am not able to share the stack trace because I am using it for my job.

The setup I'm using is stright out of the documentation:
gebVersion = '3.4'
chromeDriverVersion = '79.0.3945.36'
geckoDriverVersion = '0.26.0'
seleniumVersion = '3.14.0'

Any suggestion with this is very much appreciated. Keep up the good work!

Thomas Hirsch

unread,
May 5, 2020, 6:20:41 AM5/5/20
to Geb User Mailing List
Hi M T, 
I personally have had trouble myself making the `moveToElement()` work.
I am using mostly Chrome for some time now.
I have made good experience using these helper functions:

    void scrollIntoCenterOfScreen(Navigator navigator) {
        def yPosition = navigator.y
        def windowHeight = browser.js.'window.innerHeight'
        browser.js."window.scrollTo(0, ${yPosition - windowHeight / 2})"
    }

    void scrollToBottomOfScreen() {
        def yPosition = browser.js.'document.body.scrollHeight'
        browser.js."window.scrollTo(0, ${yPosition})"
    }


I feel that for simple cases, using JavaScript like this has a good chance of working, regardless of the frontend technology.

Best regards, 
Thomas

M T

unread,
May 5, 2020, 7:13:40 AM5/5/20
to Geb User Mailing List
Hello Thomas.

Thank you for the reply.
That works! Thank you! 
Just a sidenote for anyone wandering here:
What I am actually testing is inside iframes. The js doen't execute inside them. So just be sure to scroll BEFORE you switch to the iframes.

Thomas, you Tha Man!
Reply all
Reply to author
Forward
0 new messages