在其他节目"令牌上的语法错误"否则",删除此令牌"

时间:2016-03-11 13:38:58

标签: java

这是我的应用程序的源代码。我不明白为什么这会给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
}

2 个答案:

答案 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
 }