这是我的应用程序的源代码。我不明白为什么这会给else关键字带来错误。
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();// Launches Firefox browser with blank url
driver.get("http://www.gcrit.com/build3/admin/login.php");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin@123");
driver.findElement(By.id("tdb1")).click();
String url = driver.getCurrentUrl();
if(url.equals("http://www.gcrit.com/build3/admin/index.php"));
{
System.out.println("LOgin Successful--PASS");
}
else
{
System.out.println("Login Unsuccessful--FAIL");
}
driver.close();// Closes the browser
}
答案 0 :(得分:2)
删除;
中的if(url.equals("http://www.gcrit.com/build3/admin/index.php"));
。所以你的代码应该是 - if(url.equals("http://www.gcrit.com/build3/admin/index.php"))
答案 1 :(得分:0)
您应该删除包含if语句的行末尾的分号。
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();// Launches Firefox browser with blank url
driver.get("http://www.gcrit.com/build3/admin/login.php");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin@123");
driver.findElement(By.id("tdb1")).click();
String url = driver.getCurrentUrl();
if(url.equals("http://www.gcrit.com/build3/admin/index.php"))
{
System.out.println("LOgin Successful--PASS");
}
else
{
System.out.println("Login Unsuccessful--FAIL");
}
driver.close();// Closes the browser
}