Selenium Tutorial – Create Java App to Find Blog Rank in Google Search Result

Welcome to the example of Blog Rank Finder application. We’ve used Selenium automation tool to create this application. Selenium is primarily used for web automation testing purpose. But virtually it can be used to implement any idea you think of around web. That’s why we’ve come up with a unique and interesting topic for Selenium tutorial.

Firstly it is a perfect example of software automated testing using Selenium. Secondly it demonstrates how to leverage Selenium in filtering Google search result. And reports the rank of a blog against a keyword. We brought this idea because it is suited for software automated testing and relevant for bloggers as well.

We request readers to read it carefully as it will help them boosting their skills in software automated testing. And if you are a blogger, you can try it to find ranking of your blog for a specific keyword in Google search result. This is completely a practical Selenium tutorial which will cover all steps to create a Selenium project. Hence this Selenium tutorial is a little different from the stuff available on other websites.

What is Blog Rank or Blog Post Rank in Google Search Result?

Blog rank is the location of a blog in Google Search Result when a search is made with some keyword. It could be useful for newbie bloggers who want to see how their post is fairing in Google Search Result.

How the Blog Rank Finder application will work?

Let’s understand the functionality of the application in detail. The blog rank finder application will be a command line application. It will require three inputs before it displays the blog location in Google search result. You would be able to execute the application from the Eclipse IDE and from the command line as well.

The three inputs that the application will need are:

  • Name of the blog or website which you want to check rank for.
  • The search keyword for Google search.
  • The search threshold value or the number of pages to crawl.

Let’s now watch over the steps that you should be doing to create the blog rank finder application. We’ve split the build process in four steps to give more clarity for our readers. We’ve kept the step description quite clear so that you can easily imitate all the steps given here in your working environment.

Selenium Tutorial (Step#1) – Create a Java Project using Eclipse.

Start Eclipse and create a new “Java” project as shown in below screen shot.

Selenium Tutorial – Create Google page rank project_in_Eclipse

Assign project a name say “GooglePageRankFinder” and save.

Selenium Tutorial – Give Project name as GooglePageRankFinder

Selenium Tutorial (Step#2) – Add Selenium libraries (jar files) to your project.

If you already have the required libraries on your system then skip to the next sub step. Otherwise to read details on downloading and adding libraries, please visit the below URL.

List of Jar Libraries Required to Build Selenium WebDriver Project in Java

For adding libraries to the project, right click on the it and Select “Build Path>>Add Libraries” to add them.

Selenium Tutorial – Configure Build Path option to add required selenium libraries

Please refer to the snap shot given below. It will help you to select and add the libraries.

Selenium Tutorial – Select all libraries in the Lib folder in Project

For your note, we are using Firefox WebDriver in this demonstration. So you must have the Firefox browser on your system to run this application.

Selenium Tutorial (Step#3) – Add source code to the project.

So far we’ve added the libraries but there is still no source code. To add the source, please do the following sub steps.

  • Right click on the project’s “src” folder and select a “Package” to add.
  • Name the new package as “rankFinder”.
  • Next, select the “rankFinder” package and a “Class” as “PageRank”.
  • This will get the “” file created in the project.
  • Now we’ve attached the source code of the “” in the below code snippet. You just need to copy paste the source code into your “” file.
package rankFinder;

import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class PageRank {

	private static WebDriver driver = null;
	private static WebElement element = null;

	public static void main(String[] args) {

		// create a scanner so we can read the command-line input
	    Scanner scanner = new Scanner (new InputStreamReader(;

	    //  prompt user to Enter the search criteria in Google
	    System.out.print("Enter your search keyword: \n");

	    // get their input as a String
	    String keyword = scanner.nextLine();

	    // prompt user to Enter the website to search
	    System.out.print("Enter the target Website: \n");
	    // get their input as a String
	    String websiteName = scanner.nextLine();
	    // prompt user to Enter the number of pages to search
	    System.out.print("Enter Total number of pages to search: \n");

	    // get the page number as an int
	    int pageNo = scanner.nextInt();
	    driver = new FirefoxDriver();
		Boolean found = false;
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

		element = driver.findElement("lst-ib"));
		//element.sendKeys("Selenium WebDriver Interview questions");
		int page = 0;
		while (!found && page<=pageNo){
		List<WebElement> list = driver.findElements(By.className("_Rm"));
		for(int i=0;i<list.size();i++)
		String link = list.get(i).getText();
			System.out.println("Website Found at Page" + page);
			found = true;
			System.out.println("Website Not Found in page" + page);	
		}	*/
		}catch (Exception e)
		if (!found) {
			try {
			}catch (Exception e)
		//driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
	 public static void fnHighlightMe(WebDriver driver,WebElement element) throws InterruptedException{
		  //Creating JavaScriptExecuter Interface
		   JavascriptExecutor js = (JavascriptExecutor)driver;
		   js.executeScript("arguments[0].scrollIntoView();", element);
		   //for (int iCnt = 0; iCnt < 3; iCnt++) {
		      //Execute javascript
		         //js.executeScript("arguments[0].style.border='4px groove green'", element);
		   js.executeScript("arguments[0].setAttribute('style', arguments[1]);",element, "color: red; border: 3px solid red;");
		     //    js.executeScript("arguments[0].style.border=''", element);

Finally you are successfully able to setup the project. Now it’s the time to build the application. In Eclipse, projects are built by default and class file is automatically generated. In case the auto build setting is not enabled, use Eclipse’s “Project>>Build Project” menu option to compile the application.

If you’ve correctly followed all the above steps, you should be successfully able to build the application. If there are any errors, do let us know for help.

Selenium Tutorial (Step#4) – Execute the “GooglePageRankFinder” application.

You can now run the application using the following sub steps from Eclipse.

  • Execute the application from “Run>>Run” menu. Or you can also run it using the “CTRL+F11” keyboard shortcut.
  • Alternatively, you can execute it from “Run>>Debug” menu. In debug mode, it is allowed to insert break points into the code.

After execution, the app will ask for three inputs as described earlier. Follow the attached snap shot for clarity.

Selenium Tutorial – Google page Rank input values

Once you enter the required inputs, the application will open the browser and perform the search. It’ll crawl to the page where your blog appears in Google search result. The application will select and highlight the blog link from Google search result. You can verify the output from the attached snap shot. In case the page threshold limit gets exhausted, application will return automatically.

Selenium Tutorial – Google page rank output.

Quick Wrap up of Today’s Selenium Tutorial on Blog Rank Finder.

We hope that you like the Selenium tutorial and the implementation of the blog rank finder application. You are also welcome to enhance it further to your imagination. You can alter it to run on different browsers as well. In case you fall into any issues, do text us, email us, or use the comment box given below to reach us. We’ll certainly get back at the earliest.

You can also help us by sharing this post with your friends and social media you frequently use.

Keep Sharing Be Successful!!!