Selenium Verify Scrollbar Presence Example with WebDriver

Though not much of common scenario, you may need to verify presence of scrollbar on a web page. You may come across this scenario more often if you are automating on mobile devices. This post covers a simple selenium verify scrollbar example. We have used Selenium WebDriver with Java code for this purpose.Selenium Verify Scrollbar Example

Selenium WebDriver does not provide an out of the box API for solution of this problem. However, JavaScript can be used to detect present of scrollbar on a web page. Therefore, we will be executing JavaScript code using WebDriver’s JavaScriptExecutor API. JavaScript to detect scrollbar present is as follows.

In the example that follows, we will load Google home page and verify if scrollbar gets displayed in browser window. Follow below steps to implement Selenium verify scrollbar presence example.

  • Since we need to implement JavaScriptExecutor in our test case, add below code in your test case method.
  • The above code will return a Boolean variable. We will print a message in console as per whether its true or false. Add below code to implement this.
  • After performing above steps, your whole method should look similar to below code.
  • Done. On executing the above method, a message about presence of scrollbar will be printed to console.

This is an example of how we can verify presence of scrollbar on web page. If you want to use scrollbar on web page, you can check out this tutorial.

We hope you find our Selenium Verify Scrollbar Presence Example useful in your test automation activities. Subscribe to our feed for more such useful tips in your inbox/feed.

  1. Triveni Aroli
    • Maharshi
  2. keti
  3. Ranjith
  4. Ganesh gaitonde
  5. Sam

Leave a Reply

Your email address will not be published.