ScrollToElement is not the same in Firefox as it is in Chrome

On our website, we have signup that have a footer on them that clings to the bottom of the webpage. When we scroll to an element, Chrome scrolls until the element is clearly in its view. Firefox scrolls until it is technically on the page, but it leaves it directly behind our footer, it thinks it clicks it, but it does not. My current workaround for Firefox is to do a fake click to the last item on the page and that somehow gets Firefox to scroll further down the page. I also tried to get the top position of the window and scroll to it, but that function does not work in Firefox either. There seems to be some limitations with Firefox compared to Chrome which strikes me as odd as the original Selenium was written for Firefox. Chrome does fine in all these cases.

WebUI.navigateToUrl('cannot give this url out, will post sommething more public at a later date')try {	//Firefox hack // scrolls near least element, does not select it, click twice for Chrome to de-select'FF-SignUps/Page_Cincy De Mayo 2019 Drinks and/input_siid'))'FF-SignUps/Page_Cincy De Mayo 2019 Drinks and/input_siid'))} catch(e) {	println(e)	println('cannot click element')}WebUI.verifyElementPresent(findTestObject('FF-SignUps/Page_Cincy De Mayo 2019 Drinks and/input_siid_1'), 5)'FF-SignUps/Page_Cincy De Mayo 2019 Drinks and/input_siid_1'))WebUI.verifyElementPresent(findTestObject('FF-SignUps/Page_Cincy De Mayo 2019 Drinks and/input_siid_2'), 5)'FF-SignUps/Page_Cincy De Mayo 2019 Drinks and/input_siid_2'))

Hi Todd

That’s bad – I feel your pain. Without knowing what the driver is doing it’s kinda hard to apportion blame here (to be able to submit a bug somewhere, I mean).

I’m wondering if calling window.scrollBy (in addition to and following on from scrollToElement) might help. You’d need to call it by hooking into JavaScript but that’s easy enough…

1 Like

Thank you. I will give that a shot. I did initially try to scroll an additional amount using some extra x,y coordinates directly using WebUI.getViewportTopPosition() in Katalon Studio, and then scroll down further adding the current top position to an offset value, but Firefox would not read the current position. That function would error out. I’ll try the JavaScript workaround.

This is the driver that Firefox should be using:

todd$ /Applications/Katalon\ 
1523538847064	geckodriver	INFO	geckodriver 0.19.0
1523538847069	geckodriver	INFO	Listening on

I switched to the latest Gecko driver 0.20.1 and the scrolling is much better in Firefox. And the normal WebUI code works.

WebUI.scrollToElement(findTestObject('FF-GeckDriver20-1/Page_Cincy De Mayo 2019 Drinks and/input_siid'), 5)'FF-GeckDriver20-1/Page_Cincy De Mayo 2019 Drinks and/input_siid')
WebUI.scrollToElement(findTestObject('FF-GeckDriver20-1/Page_Cincy De Mayo 2019 Drinks and/input_siid_1'), 5)'FF-GeckDriver20-1/Page_Cincy De Mayo 2019 Drinks and/input_siid_1'))

Excellent outcome. Kudos “Sherlock” :wink:

1 Like

Is there an equivalent function to scrollToElement for Windows apps? If so, what is the package?

It’s probably not a good idea to try to resurrect an almost three year old thread to ask a question about another API set. There’s a whole forum category for Windows Desktop testing…