Reputation: 77
I'm writing a Java code that would run a simple automation scenario in Chrome or Firefox - depending on the user's input. There are no underlined errors, but the program is stuck at the nextInt line (saw it in the Debugger), and there is no output. Could anyone help? Thanks!
package com.selenium;
import java.util.Scanner;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Main {
public static void main(String[] args) throws InterruptedException {
// environment variable
System.setProperty("webdriver.chrome.driver", "C:\\Automation\\libs\\Drivers\\chromedriver.exe");
//WebDriver chromeDriver = new ChromeDriver();
System.setProperty("webdriver.gecko.driver", "C:\\Automation\\libs\\Drivers\\geckodriver.exe");
WebDriver driver = null;
Scanner scanner = new Scanner(System.in);
int option = scanner.nextInt();
System.out.println("Please enter 1 for Chrome or 2 for Firefox " + option);
if (option == 1)
{
WebDriver driver1= new FirefoxDriver();
}
else if
(option == 2)
{
WebDriver driver2 = new ChromeDriver();
}
else
System.out.println("Please enter a correct number " + option);
String baseURL = "https://login.salesforce.com/?locale=eu";
driver.get(baseURL);
WebElement userName = driver.findElement(By.id("username"));
userName.sendKeys("Yan");
WebElement password = driver.findElement(By.id("password"));
password.sendKeys("123456");
WebElement rememberCheckbox = driver.findElement(By.id("rememberUn"));
rememberCheckbox.click();
WebElement bLogin = driver.findElement(By.id("Login"));
bLogin.click();
}
}
Upvotes: 0
Views: 126
Reputation: 3601
Put your System.out
before the scanner.nextInt()
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter 1 for Chrome or 2 for Firefox " + option);
int option = scanner.nextInt();
Then type 1 or 2 on the keyboard when it asks you to enter a number.
Upvotes: 2