Examples of Selenium Webdriver Scripts

Examples of Selenium Webdriver Scripts

Now its time to code and execute the selenium webdriver scripts after installation of TestNG framework successfully.

Example 1: Create a class as “Example” copy and paste the below mentioned code and right click on classname and mouse over on "Run As" option and click on  “TestNG Test” option.


package Newpack;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;

public class Example  {

            public String baseUrl= "http://www.google.com/";

            public WebDriver driver = new FirefoxDriver();


public void verifyHomePageTitle() {


        // Find the text input element by its name

        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for



        // Now submit the form. WebDriver will find the form for us from the element


        // Check the title of the page

        System.out.println("Page title is: " + driver.getTitle());





Results of running the Testng Test Case

13. Give it few minutes to complete the execution, once it is finished the results will look like this in the TestNg Result window.


It displayed ‘passed: 1′. This means test is successful and passed.

There are 3 sub tabs. “All Tests”, “Failed Tests” and “Summary”. Just click “All Tests” to see what is there.

all test

There is information of which test cases are executed and their duration.

14. TestNG also produce HTML reports. To access those reports go to test-output folder and open ‘emailable-report.html‘, as this is a html report open it with browser.


15. TestNG also produce ‘index.html‘ report and it resides in the same test-output folder. This reports gives the link to all the different component of the TestNG reports like Groups & Reporter Output. On clicking these will display detailed descriptions of execution. In the advance chapter of TestNG we will go though each of the TestNG topics.


Example 2: Create a script for Login and logout scenario as shown below and right click on classname and mouse over on "Run As" option and click on  “TestNG Test” option.


package com.test.webdriver;

import static org.testng.AssertJUnit.assertEquals;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test; 

public class Driver {

private WebDriver driver;


 public void Startup(){

  driver = new FirefoxDriver();


 @Test (description="Google Login")

 public void GoogleLogin() throws Exception{


  assertEquals("Sign in", driver.findElement(By.id("signIn")).getAttribute("value"));









assertEquals("Sign in to Gmail", driver.findElement(By.id("button")).getText());



 public void teardown(){






Connect apps and integrate data with workflows using Azure Logic Apps

Implementing complex business process has been made easy. Logic Apps in azure provide a way to imple...

Read More >

TFS to VSTS Migrations

The next evolution of TFSWhether you’re a startup or Enterprise or you’re a team of just...

Read More >

CfMD services -Dynamics NAV

CfMD services help ISVs minimize the time and effort needed to get their software solution through t...

Read More >

Upcoming Webinar - Offshore support to North American Dynamics NAV partners

Offshore support to North American Dynamics NAV partners whose customers are moving to NAV '16Wh...

Read More >

Microsoft Azure Consultant

·         Executing technical feasibility as...

Read More >

Customer Feedback

Your feedback is important to us. Please share your experience working with Canarys & the journe...

Read More >


Multi-taskingIt is a concept of performing multiple tasks over a certain period of time by executing...

Read More >

Partnership Program

We understand that the world of technology is changing rapidly from day to day and businesses have m...

Read More >

Partnership Program

The Canarys Partner Program:Canarys is all set to expand its business reach across the Globe and is ...

Read More >

Upcoming Webinar US - Plugging for Cloud, Right or Wrong

Plugging for Cloud, Right or Wrong?Cloud computing continues to be one of the most advertising topic...

Read More >



thanks for sharing valuable information... Internet of Things(iot) in coimbatore IOT Training in coimbatore Top 10 IOT training institute in coimbatore Internet of Things(iot) training course in coimbatore Internet of Things(IOT) course in coimbatore Best iot training in coimbatore iot application training in coimbatore iot based projects in coimbatore iot online training in coimbatore iot training near me Best iot training institute in coimbatore Internet of Things(iot) course in coimbatore Internet of Things course training in coimbatore
5/20/2021 1:10:42 PM | Reply
I feel really happy to have seen your webpage and look forward to so many more Information reading here best CCNA Training In Chennai CCNA Training In Chennai Java Course Syllabus
3/27/2021 12:36:02 PM | Reply
Good and informative blog.
3/4/2021 5:07:09 PM | Reply
Great information, it has an impressive range of content. Keep Posting.
2/23/2021 11:46:19 AM | Reply
hello there and thank you for your iformation – I have certainly picked up anmything new from right here. I did however expertise a feww technical points using this site, since I experienced to reeload the website a lot of times previous to I could get it to load correctly.I had been wondering if your web hosting is OK? Not that I'm complaining, but sluggush loading instances times will sometimes affect your placement in google and could damage your high quality score if advertising and marketing with Adwords.Anyway I'm adding this RSS too myy e-mail and can look out for much more of our respective fascinating content.Ensure that you update this again very soon.https://www.patreon.com/posts/44362170how to make essayhow tto make essay
2/8/2021 2:49:35 PM | Reply
Wow, you have covered all the fundamental examples in this blog. I would also like to suggest that driver.get() : is used to go to the particular website, but it doesn't maintain the browser History and cookies so, we can't use the forward and backward button, if we click on that, the page will not get scheduled
2/5/2021 5:44:32 PM | Reply
This blog gives the knowledge of selenium webdriver and advance concepts. I am searching for such kind of blogs and all these sites are really good. Thanks for sharing this blog.
1/26/2021 1:55:22 PM | Reply
Great content.
1/12/2021 12:34:54 PM | Reply
Nice to get scripts on selenium. It is helpful.
9/22/2020 2:55:36 PM | Reply
Very informative post. You are including good information regarding this topic in an effective way. Thanks. it was a wonderful chance to visit this kind of site and I am happy to know.Also visit for information: https://www.rcvacademy.com/
9/15/2020 3:35:31 PM | Reply
Muchas gracias. ?Como puedo iniciar sesion?
7/27/2020 4:10:45 PM | Reply
Muchas gracias. ?Como puedo iniciar sesion?
7/24/2020 8:04:40 PM | Reply
great information thank you for shearing for this post if you have additional information please post it.
7/22/2020 5:12:47 PM | Reply
This great article has really peaked my interest. I am going to book mark your blog and keep checking for new information about once per week. https://www.acte.in/selenium-training-in-chennaihttps://www.acte.in/selenium-training-in-annanagarhttps://www.acte.in/selenium-training-in-omrhttps://www.acte.in/selenium-training-in-porurhttps://www.acte.in/selenium-training-in-tambaramhttps://www.acte.in/selenium-training-in-velachery
6/19/2020 11:30:51 AM | Reply
Thanks for this blog, I'am very much delighted to say that this blog has helped me a lot in gain some extra knowledge. Selenium Training in chennai | Selenium Training in anna nagar | Selenium Training in omr | Selenium Training in porur | Selenium Training in tambaram | Selenium Training in velachery
6/19/2020 11:29:33 AM | Reply
Page 1 of 3 FirstPrevious [1]23 Last

Post a Comment

Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Monthly Archive

Contact Us
  • *
  • *