Scroll to Element , Scroll By, and Scroll To is not working

I started using Browser Library on my automation. I enjoyed using it compared to selenium as this is faster. But now I encountered a bottleneck, Scroll to Element, Scroll By, and Scroll to is not working. I needed the scroll functions to continue with my automation as i need to test certain element in the middle of the webpage. I know that the selector that i used is correct because when I tried to manually scroll during automation run, the tests will pass. Here is my sample code
Translate Text
[Arguments] ${language} ${category} ${text}
${translated_text} = get_value_from_excel ${category} ${language} ${text}
Scroll To Element ${PO_${text.replace(’ ', ‘').upper()}}
${web_text} = Get Text ${PO
${text.replace(’ ', ‘_’).upper()}}
Should Be Equal ${web_text} ${translated_text}

And here is the error message:

TimeoutError: locator.scrollIntoViewIfNeeded: Timeout 10000ms exceeded.
Call log:

  • waiting for locator(‘.categorieshomerecentlyplayed’

Could you actually share the whole call log ?

EDIT:

Also worth pointing out, if the element with that selector is being “lazy-loaded”, scrolling into it with actual locator probably will not work.

Maybe the website uses some kind of lazy loading, where the element you are looking for gets only loaded when you scroll down.

@rasjani What do you mean by call log? where can I see that?

Regarding on the behavior of the website, i notice that when i scroll down manually, new request were being sent to the backend, after that request was process, it will then show in UI. Is that the Lazy-loaded you are referring to?

Thank you for the quick response

@falcon030 yes exactly. How can I deal with that?

Yes, that’s exactly lazy-loading.

https://marketsquare.github.io/robotframework-browser/Browser.html#Scroll%20To

Scroll To kw can scroll to bottom and it also mentions about lazy loading

Thanks for providing the link. I read and follow the instruction on how to use Scroll To but it still doesn’t work. This is my code for the Scroll To kw:
Scroll To ${None} bottom left auto

but unfortunately, I still encounter this error:
TimeoutError: locator.scrollIntoViewIfNeeded: Timeout 10000ms exceeded.

Is there some settings that I am missing?

Single scroll to bottom might not be enough. I’d approach this by creating to a keyword that does that scroll to bottom and then check if element is there and if not, fail the keyword… then use Wait Until keyword succeeds to call that new keyword multiple times until element is found OR timeout/ iteration limit is reached (and thus, failing)

Scroll To ${None} bottom left auto

Also that doesn’t look like how it’s supposed to be called

Scroll To    vertical=bottom

Maybe ?

@jolo26 You can use something like the following example:

Lazy loading
    New Browser  browser=chromium  headless=False
    New Context
    New Page    url=https://www.visitflorida.com/beaches
    ${browserHeight}  Evaluate JavaScript  ${None}  window.innerHeight  
    ${pageHeight}  Evaluate JavaScript  ${None}  document.body.scrollHeight  

    VAR    ${selector}    //img[@src="https://assets.simpleviewinc.com/simpleview/image/upload/c_fill,f_jpg,h_284,q_55,w_360/v1/clients/visitflorida/Sunset_Islamorada_Florida_Keys_ce53f890-53b3-4cf1-a0ac-4f12a5e3b7ad.jpg"]

    FOR    ${scroll_range}    IN RANGE    0    ${pageHeight}    ${browserHeight}
        Mouse Wheel    0    ${browserHeight}
        ${element_visible}  Get Element States    ${selector}    then    bool(value & visible)
        IF  ${element_visible} == ${True}  BREAK
    END
    Click  ${selector}

If you disable the FOR block, the script won’t work because the element is then not present.

1 Like

Still does not work on the website that Im working on. I think there are functionality that prohibits the Scroll to to work properly. But the Mouse wheel work as suggested by @falcon030 . Thanks to both of you for the help :slight_smile:

This works on my project. Thank you so much :slight_smile:

2 Likes