How to put the code in Selenium | Selenium me Code Kaise dale.

IF you want to put the code on to the selenium then we required to install selenium firstly and then we can use it selenium jare Labarriere

so Firstly we have interface in that we have code as per following in that way we can add a code


package selenium29_10_22;

public interface CommanThings {
//Declaring instance variable but it act as static variable
String key1 = “”;
String key2 = “webdriver.edge.driver”;
String value1 = “D:\chromedriver.exe”;
String value2 = “D:\msedgedriver.exe”;
String url = “”;

    //Declaring default non static method 
    //but it should be always complete
    default void welcome () {
        System.out.println("Welcome to Testing");
    //declaring non static method but it should be always incomplete
    void chromelaunch ();
    void edgelaunch ();
    //declaring default non static method 
    default void end () {
        System.out.println("Testing Has been Done");

Implements Class

package selenium29_10_22;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class ImplementsClass implements CommanThings{
//We need to complete incomplete method means abstract Methods
//and also we will declare object here of webdriver only LHS side
static WebDriver ob;
//then we go for completing non static method
public void chromelaunch () {
//Firstly we need to set the property
//then we need to set the object only RHS Side
ob = new ChromeDriver();
//Then We maximize Window
//then we are going to delete the cookies
//Then We need to hit the url for that
//we can also use get method or navigate method
//but we use navigate method coz navigate is kind of dynamic method

//Completing second method for edge
public void edgelaunch () {
    //first we need to set property of driver like we set any driver 
    //using with help of key and value 
    System.setProperty(key2, value2);
    //Then We need to declare object of driver
    ob = new EdgeDriver();
    //Then we required to maximize window
    //then we going to delete all cookies also 
    //Then We need to hit the url for that wwe have two different types method
    //1 is get method and another one is navigate method with the help of this we can also do
    //but mostly we use navigate method for hit the url
    //so that's the way we can hit the url

Scenario Class

package selenium29_10_22;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import java.util.Set;
public class Scenario1 extends ImplementsClass {
	String expTitle = "Selenium Practise: Multiple window examples";
	String expUrl = "";
	public void google () throws InterruptedException {
		//firstly i will check my tile is it correct or not for that i will use
		//getTitle method and i will store this are thing inside the variable
		//Using a String Non primitive Data Type
		String actTitle = ob.getTitle();
		//For checking Purpose i need to use if else Control statement
		//for condition Checking purpose i need also expected tile 
		//so expected title provided by developer 
		if (actTitle.equals(expTitle)) {
			System.out.println("Title Is match = " + actTitle);
		else {
			System.out.println("Title is not match = " + actTitle);

		//For Second Thing We need to check also a url as per expected or not
		//For that we also have one kind of method it nothing but a 
		//And This current Url we are going to store inside the variable
		String actUrl = ob.getCurrentUrl();
		//For checking purpose i will use if else condition
		if (actUrl.equals(expUrl)) {
			System.out.println("Url is Match = " + actUrl);
		else {
			System.out.println("Url Is not Match = " + actUrl);
		//for find the window id i will use as getWindowHandle with the help of we can
		//find out only one window id and only one parent window id
		String parentid = ob.getWindowHandle();
		//With the help of locator we are going to find out web element
		WebElement vari1 = ob.findElement(By.xpath("html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div/div/div/div/div/div/div/div/div[1]/div[2]/a[1]"));;
		//After Shifting to other window we need to find out other window id right
		//for that we also one type method it is nothing but getWindowHandles
		//in that it will give two window id first is parent window id and second one is child 
		//window id so in that we are storing multiple id so we required multiple string 
		//So for that we also have interface that is nothing but set we will use it
		//and set is a class we need to import also
		Set<String> parentandchildid = ob.getWindowHandles();

		//So for differentiate we going to use for each loop
		for (String ec: parentandchildid) {
			//so for filter or focus on new window we need to use if else Condition
			if (!parentid.equals(ec)) {
				//Then we will get new window id with help of this if condition
				//then we need to be switch the window
				//then our focus will be shift to new window
				WebElement var1 = ob.findElement(By.xpath("//input[@name= 'q']"));
				var1.sendKeys("Java History");
				//Then we are going to click on search
				//				WebElement var2 = ob.findElement(By.xpath("//input[contains(@data-ved,'0ahUKEwik18Wdq4X7AhWLE4gKHb_GBicQ4dUDCAg')]"));

				WebElement var3 = ob.findElement(By.xpath("//li[@class='sbct']"));;
		//Then we need to switch window as previous
		//then i am going to click other web element
		WebElement var4 = ob.findElement(By.xpath("//a[contains(text(),'2022')]"));;
		//Now We are going to back

	//New Scenario new method
	public void facebook () throws InterruptedException {
		String actTitle = ob.getTitle();
		if (actTitle.equals(expTitle)) {
			System.out.println("Title is match = " + actTitle);
		else {
			System.out.println("Title Is not Match = " + actTitle);

		String actUrl = ob.getCurrentUrl();
		if (actUrl.equals(expUrl)) {
			System.out.println("Url is Match = " + actUrl);
		else {
			System.out.println("Url is Not Match = " + actUrl);

		//for getting parent Window id
		String parentID = ob.getWindowHandle();
		//Then we Click on next WebElement
		WebElement var1 = ob.findElement(By.xpath("html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div/div/div/div/div/div/div/div/div[1]/div[2]/a[2]"));;
		//Then We Are on next or new Window
		//Then we need to find out both WebElement Id for That we have one 
		//getWindowHandles Method
		Set<String> ParentandChildID = ob.getWindowHandles();
		for (String oh: ParentandChildID) {
			//Then we will use if else statement
			if (!parentID.equals(oh)) {
				//Then we Need to switch the focus for That we have method
				//after That We will find out webElement of Fb WebPage
				//for Input Or password
				WebElement var2 = ob.findElement(By.xpath("//input[contains(@name,'email')]"));
				//Next webElement as password
				WebElement var3 = ob.findElement(By.xpath("//input[contains(@name,'pass')]"));
				//Then we Need to click on the Log in button
				WebElement var4 = ob.findElement(By.xpath("//button[contains(@name,'login')]"));;
				//We will use Here Sleep Method 
				//after that i will close this Window
		//We required to go on previous tab for that we will use Switch method
		WebElement var5 = ob.findElement(By.xpath("//a[contains(text(),'2021')]"));;

	//For Next application we will use new method
	public void FB () {
		//Firstly We required check the title and url 
		//		ob.manage().deleteAllCookies();
		String actTitle = ob.getTitle();
		if (actTitle.equals(expTitle)) {
			System.out.println("Title is Match = " + actTitle);
		else {
			System.out.println("Title is not Match = " + actTitle);

		//Then We will going to check url 
		String actUrl = ob.getCurrentUrl();
		if (actUrl.equals(expUrl)) {
			System.out.println("Url is Match = " + actUrl);
		else {
			System.out.println("Url is not Match = " + actUrl);

		//Firstly We need to find out Window ID
		String parentID = ob.getWindowHandle();
		//For finding WebElement We will use xpath Relative xpath by contains by text function
		WebElement var1 = ob.findElement(By.xpath("//a[contains(text(),' Click this link to start  Session in same window')]"));;

		//Then we need to find out child window id 
		//so with The help of getWindowHandles Method we can find out both Windowid
//		Set<String> parentandchildID = ob.getWindowHandles();
		//And the We Focus on Next Window for that we will use for each loop
//		for (String ec : parentandchildID) {
//			if (!parentID.equals(ec)) {
				//Then We need to change focus of window
//				ob.switchTo().window(ec);
				//Then We are on next WebPage FB
				//after that we required to find out input WebElement
				WebElement var2 = ob.findElement(By.xpath("//input[@name='email']"));
				//Now we need to find out WebElement of Password
				WebElement var3 = ob.findElement(By.xpath("//input[@name='pass']"));
				//Then We need to find WebElement of Login Button 
				WebElement var4 = ob.findElement(By.xpath("//button"));;
				//Searching at FB Search option
				WebElement var5 = ob.findElement(By.xpath("//input[@class='x1i10hfl xggy1nq x1s07b3s x1kdt53j x1yc453h xhb22t3 xb5gni xcj1dhv x2s2ed0 xq33zhf xjyslct xjbqb8w x6umtig x1b1mbwd xaqea5y xav7gou xnwf7zb x40j3uw x1s7lred x15gyhx8 x9f619 xzsf02u xdl72j9 x1iyjqo2 xs83m0k xjb2p0i x6prxxf xeuugli x1a2a7pz x1n2onr6 x15h3p50 xm7lytj x1sxyh0 xdvlbce xurb0ha x1vqgdyp xo6swyp x1ad04t7 x1glnyev x1ix68h3 x19gujb8']"));
				var5.sendKeys("Manoj More");
				//Then we will click on the search option
				WebElement var6 = ob.findElement(By.xpath("//strong[contains(text(),'Manoj More')]"));;
//			}
//		}

Execution Class

package selenium29_10_22;

public class ExecutionClass extends Scenario1{
	public static void main(String[] args) throws Exception{
		ExecutionClass obj = new ExecutionClass();

its the way to do a selenium testing How to put the code in Selenium.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

7th day of Navratri 10-2-2022 Sanjay Raut: संजय राउत के घर रविवार सुबह पहुंची ED, President Draupadi Murmu Vedanta declares dividend of Rs 19.5 per share CBSE 10th 12th Results 2022-जारी होने वाला है