Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

jQuery scroll to element

jQuery scroll to element

When you manually test something at the bottom of the page first you need to Scroll and second you start interacting with your Element , so does selenium. By default selenium actively scrolls to the element that needs to perform actions but you might end up having issues most of them happen on Firefox but even in Google chrome. So in this situation you need a stable method to scroll to the element  and after perform the next selenium action that you want.

I will provide the code in ruby using Capybara but you can easily adapt it to any other programming languages.

 # Scroll to any element/section
    # @param element [Capybara::Node::Element, SitePrism::Section]
    def scroll_to(element)
      element = element.root_element if element.respond_to?(:root_element)
      Capybara.evaluate_script 
So what is a root_element?

The css selector that is passed as the 3rd argument to the sections method (“#results li”) is used to find a number of capybara elements. Each capybara element found using the css selector is used to create a new instance of the SearchResultSection and becomes its root element. So if the css selector finds 3 li elements, ccallingsearch_results will return an array containing 3 instances of SearchResultSection, each with one of the lielements as it’s root element.

If you are wandering about root_element , you can consult site prism git hub page for more details .

You can enjoy reading a pair of  articles part of the selenium tips bunch:  Capybara get attribute or Tellurium selenium .

Happy testing people!

The post Jquery Scroll to element appeared first on TestingRepository.



This post first appeared on Testing Repository - Creating Testing, please read the originial post: here

Share the post

jQuery scroll to element

×

Subscribe to Testing Repository - Creating Testing

Get updates delivered right to your inbox!

Thank you for your subscription

×