Do you need scroll the page ? (Selenium and javascript)

If you need scroll the page for example take a screenshot in a browser different of Firefox (Yes, the selenium have a problem to take a screenshot of the entire page when you are in a different browser like, IE)

So we have to create a function that take a screenshot of parts of the page, and this function helps you to scroll the page.

First you have to import the libraries:

import org.openqa.selenium.JavascriptExecutor;


After the code:

JavascriptExecutor js = (JavascriptExecutor) driver;
+ “document.body.scrollHeight,document.documentElement.clientHeight));”);


After this, the driver will scroll until the end of the current page.

I hope that I help you 🙂

Mark element in the page with red border (Javascript with Selenium)

Hello again, now I will give a tip of Selenium, for mark the element that you want and before this, you can take a screenshot for evidence.

First you have to import this libraries:

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;


After this, you have to call the javascript executor and give the id or other thing for find the element:

JavascriptExecutor js = (JavascriptExecutor) driver; // change the name of your WebDriver
WebElement element = driver.findElement(“element“)); // change the localizator 

js.executeScript(“arguments[0].style.border=’3px solid red'”, element); // change the name of your variable


This is very usefull for mark the element in the page.

So, just this ! Bye bye 🙂

What a constructor do ?

Hum.. I always forget the function of a constructor because I don’t have the custom to use.

For this reason, I will put here some tips:

A constructor  is a method with instructions that will execute ALWAYS  when will instantiated a object of this class.

Like this:

  • Class
 public class MyClass {

public MyClass() { //this is the constructor method
System.out.println(“Hello World !”);
}  }

In the constructor method will be wrrte “Hello World !”

So… when you call this class, the constructor will be execute.


  • Class
 public class Test {

public static void main(String args[]) {
MyClass Obj1 = new MyClass();

It’s simple no ? It is just a method that will be execute before others methods when you call this class.
Bye bye !