Search code examples
pythonrobotframework

How to scroll a particular element(see attached image) horizontally in robot framework?


I am able to scroll window, but is there any way to scroll some specific element(like grid) present in window? The grid too has scroll bar similar to window as shown in image below

I found this solution.

Execute Javascript |  window.document.getElementById("your id goes here").scrollIntoView(true);

But unfortunately 'id' is not defined in my case for that particular element(grid) I want to scroll. Is there any other solution, I tried a lot, but no success yet.

enter image description here

HTML tag for scroll bar enter image description here


Solution

  • Use the following one

    Execute JavaScript | window.document.getElementById('your element id').scrollLeft += 250

    (OR)

    Execute JavaScript | window.document.getElementsByClassName('your element class name')[0].scrollLeft += 250

    (OR)

    Execute JavaScript | document.getElementsByName('your element name ')[0].scrollLeft += 250

    (OR)

    Execute JavaScript | document.getElementsByTagName('your element tagname')[0].scrollLeft += 250

    (OR) Execute JavaScript | document.querySelector('your element CSS selector').scrollLeft += 250

    you can use any of the solution, not like Id or querySelector all other will give array of elements matches, so need to pass the index.

    querySelector will give the first match element, so here not required to give index.

    scrollIntoView() - Scrolls the specified element into the visible area of the browser window scrollLeft - Sets or returns the number of pixels an element's content is scrolled horizontally

    Hope this will solve your problem