Selenium
Selenium
package BATCH1;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class DemoSearch {
public static void main(String[] args) throws
InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
"D:\\Selenium\\chromedriver-win64\\chromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("https://www.w3schools.com/");
wd.manage().window().maximize();
wd.findElement(By.xpath("/html/body/div[5]/div[1]/div/div/div/div[1]
/div/form/input")).sendKeys("Python tutorial");
Thread.sleep(2000);
wd.findElement(By.xpath("/html/body/div[5]/div[1]/div/div/div/div[1]
/div/form/button")).click();
}
}
Output :
Problem Statement:
Cross Browsing using switch case.
Code :
package BATCH1;
import java.util.Scanner;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class DemoCrossBrowser {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// TODO Auto-generated method stub
System.out.println("1- Chrome");
System.out.println("2 - Edge");
int i =sc.nextInt();
switch(i) {
case 1 :
System.setProperty("webdriver.chrome.driver",
"D:\\Selenium\\chromedriver-win64\\chromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("https://www.somaiya.edu/en/");
wd.manage().window().maximize();
break;
case 2 :
System.setProperty("webdriver.edge.driver",
"D:\\Selenium\\msedgedriver.exe");
WebDriver wd1 = new EdgeDriver();
wd1.get("https://www.google.co.in/");
wd1.manage().window().maximize();
break;
}
}
}
Output :
On Choosing option 1 :
On Choosing option 2 :
20/3/25
package batch1;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class demolocator {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
"D:\\Selenium\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("https://www.tutorialspoint.com/index.htm");
wd.findElement(By.id("search-strings")).sendKeys("hello");
wd.findElement(By.id("search-strings")).sendKeys("/n");
wd.manage().window().maximize();
}
}
package Batch1;
import java.util.Scanner;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class DemoCrossBrowser {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("1: Chrome");
System.out.println("2: Edge");
int ch = sc.nextInt();
switch(ch) {
case 1:
System.setProperty("webdriver.chrome.driver","D:\\Selenium\\chromedriver-win64\\chromedriver-win64\\c
hromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("https://www.w3schools.com/");
wd.manage().window().maximize();
break;
case 2:
System.setProperty("webdriver.edge.driver","D:\\Selenium\\edgedriver_win64\\edgedriver_win64\\msedge
driver.exe");
WebDriver wd2 = new EdgeDriver();
wd2.get("https://www.w3schools.com/");
wd2.manage().window().maximize();
break;
default:
System.out.println("Invalid Option!");
}
}
}
package Batch1;
import java.util.Scanner;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class DemoSearch {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","D:\\Selenium\\chromedriver-win64\\chromedriver-win64\\c
hromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("https://www.w3schools.com/");
wd.manage().window().maximize();
wd.findElement(By.xpath("/html/body/div[5]/div[1]/div/div/div/div[1]/div/form/input")).sendKeys("Python
tutorial");
wd.findElement(By.xpath("//*[@id=\"learntocode_searchicon\"]")).click();
}
}