Open Browsers based on Keyboard Input
Sat Apr 15 2023 11:49:43 GMT+0000 (Coordinated Universal Time)
Saved by @Sai_Koushik
package com.magnitia.gmail.JavaProject;
import java.util.Scanner;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class Hello {
//lets open browsers based on our keyboard input
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // creates a new instance of the Scanner class that reads input from the keyboard and assigns it to the ref variable sc
String num = sc.nextLine(); //sc.nextLine() is a method of the Scanner class in Java that reads the entire line from keyboard and returns it as a String with a ref variable num
sc.close(); //closing keyboard inputs
if (num.equalsIgnoreCase("chrome")) //The code checks if the user input is "chrome" (ignoring case) and if it is true, launches a new instance of the Chrome web browser using Selenium WebDriver.
{
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
}
else if (num.equalsIgnoreCase("Edge")) { //The code checks if the user input is "Edge" (ignoring case) and if it is true, launches a new instance of the Chrome web browser using Selenium WebDriver.
WebDriverManager.edgedriver().setup();
WebDriver driver = new EdgeDriver();
}
else if (num.equalsIgnoreCase("FireFox")) { //The code checks if the user input is "Firefox" (ignoring case) and if it is true, launches a new instance of the Chrome web browser using Selenium WebDriver.
WebDriverManager.firefoxdriver().setup();
WebDriver driver = new FirefoxDriver();
}
else if (num.equalsIgnoreCase("Brave")) { //The code checks if the user input is "Firefox" (ignoring case) and if it is true, launches a new instance of the Chrome web browser using Selenium WebDriver.
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
}
else {
System.out.println("Wrong Entry"); //if any input other than chrome or edge or firefox , is prints as metioned
}
}
}



Comments