Selenium how to scroll to the position of the specified element in the window

Source: Internet
Author: User

1, a window of some elements can not be seen in the display of the page, the need to scroll the scroll bar to display it,

This way the selenium is not directly anchored to the element.

Two workarounds:

One: Using JS to execute

=(javascriptexecutor) driver;js.executescript ("Arguments[0].scrollintoview ();", Coursepage.getviewdetails (). Get (0));

This method is to display the window directly to the target element and the following elements. The topmost display element of the window.

Ii. use of actions. Move to Element action

Actions.movetoelement (Coursepage.getviewdetails (). Get (0)). Build (). Perform ();

This method causes the element to be displayed at the bottom of the window.

Selenium how to scroll to the position of the specified element in the window

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.