Thursday, January 27, 2022

Selenium Basic Example

Selenium 

Selenium is one of the most widely used open source Web UI (User Interface) automation testing suite.It was originally developed by Jason Huggins in 2004 as an internal tool at Thought Works. Selenium supports automation across different browsers, platforms and programming languages.

Selenium WebDriver is the most important component of Selenium Tool's Suite. The latest release "Selenium 2.0" is integrated with WebDriver API which provides a simpler and more concise programming interface.

The following image will give you a fair understanding of Selenium components and the Test Automation Tools.


Selenium WebDriver

Selenium WebDriver was first introduced as a part of Selenium v2.0. The initial version of Selenium i.e Selenium v1 consisted of only IDE, RC and Grid. However, with the release of Selenium v3, RC has been deprecated and moved to legacy package.

In WebDriver, test scripts can be developed using any of the supported programming languages and can be run directly in most modern web browsers. Languages supported by WebDriver include C#, Java, Perl, PHP, Python and Ruby.



Example

import java.awt.RenderingHints.Key;


import org.openqa.selenium.By;

import org.openqa.selenium.Keys;

import org.openqa.selenium.WebDriver;  

import org.openqa.selenium.chrome.ChromeDriver;  

public class test {


public static void main(String[] args) {

// TODO Auto-generated method stub

// declaration and instantiation of objects/variables  

    System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\chromedriver.exe");  

    WebDriver driver=new ChromeDriver();  

      driver.get("https://google.com");

// Launch website  

    

          

    // Click on the search text box and send value  

    driver.findElement(By.name("q")).sendKeys("devops");  

    driver.findElement(By.name("q")).sendKeys(Keys.ENTER);

    // Click on the search button  

    driver.findElement(By.name("btnK")).click();  

      

    }  

}

0 comments:

Post a Comment