scolling an element using Execute Javascript

3,807 views
Skip to first unread message

Rob Bovill

unread,
Mar 29, 2013, 3:04:49 PM3/29/13
to robotframe...@googlegroups.com
     Does anyone know how to scroll an element (a list) using Execute Javascript in Selenium WebDriver (selenium2library)?  I can reference the element using css, xpath, and maybe DOM.  I just don't know JavaScript, and there seems to be a lot of problems with this particular functionality, so the documentation I've found has been helpful.

thanks,

Rob

Rob Bovill

unread,
Mar 29, 2013, 4:07:31 PM3/29/13
to robotframe...@googlegroups.com
      Sorry, I meant to say "so the documentation I've found has not been helpful."

Markus Bernhardt

unread,
Apr 1, 2013, 7:21:05 AM4/1/13
to rbo...@gmail.com, robotframe...@googlegroups.com
Hi Rob,

I'm not 100% sure what you want to do. If you want scrolling a located element of a list into view, you could try:

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

with xpath:
    Execute Javascript    window.document.evaluate("your xpath goes here", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView(true);

That should do the trick.

Hope that helps somehow,
Markus
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jason Tran

unread,
Dec 9, 2013, 3:59:38 PM12/9/13
to robotframe...@googlegroups.com, rbo...@gmail.com
Hi Markus and all,

What I am trying to accomplish:
1. Click a dropdown menu
2. Scroll down (as the item I want to select is not visible)
3. Select an item from dropdown menu

Using the command that Markus posted doesn't seem to work on my case:

Execute Javascript window.document.evaluate("xpath=//.jspPane > li:nth-child(6)", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView(true);

Using Firefox inspector, I found the item I want is: .jspPane > li:nth-child(6).

Thanks,


On Monday, April 1, 2013 4:21:05 AM UTC-7, Markus Bernhardt wrote:
Hi Rob,

I'm not 100% sure what you want to do. If you want scrolling a located element of a list into view, you could try:

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

with xpath:
    Execute Javascript    window.document.evaluate("your xpath goes here", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView(true);

That should do the trick.

Hope that helps somehow,
Markus

Am 29.03.2013 um 21:07 schrieb Rob Bovill:

      Sorry, I meant to say "so the documentation I've found has not been helpful."

On Friday, March 29, 2013 12:04:49 PM UTC-7, Rob Bovill wrote:
     Does anyone know how to scroll an element (a list) using Execute Javascript in Selenium WebDriver (selenium2library)?  I can reference the element using css, xpath, and maybe DOM.  I just don't know JavaScript, and there seems to be a lot of problems with this particular functionality, so the documentation I've found has been helpful.

thanks,

Rob

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

reva revathi

unread,
Mar 30, 2015, 6:36:18 AM3/30/15
to robotframe...@googlegroups.com, rbo...@gmail.com
Hi Markus,
     
    I have used the below mentioned keyword for scrolling.
Execute Javascript    window.document.evaluate("your xpath goes here", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView(true);
But it didn't work fine, displayed error
"WebDriverException: Message: unknown error: Runtime.evaluate threw exception: SyntaxError: Unexpected identifier
(Session info: chrome=41.0.2272.101) (Driver info: chromedriver=2.13.307647 (5a7d0541ebc58e69994a6fb2ed930f45261f3c29),platform=Windows NT 6.1 SP1 x86)"
please suggest a solution for this.
Reply all
Reply to author
Forward
0 new messages