[Solved] Syntax error on token “else”, delete this token [closed]


your code is missing braces ( that’s these: {} BTW). It’s ok if your if statement involves only a single line, however i’d advise to use them anyway for readability.

Overall, your code should look similar to:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;


public class gg {

  public static void main(String[] args)
  {


     String browser = "Chrome";

     WebDriver driver = null;

     if(browser.equals("Mozilla"))
     {
      driver = new FirefoxDriver();
     }
     else 
     {
         if(browser.equals("Chrome"))
         {
            System.setProperty("webdriver.chrome.driver", "F:\\chromedriver_win32\\chromedriver.exe");
            driver = new ChromeDriver();
         }
         else
         {
            if(browser.equals("IE"))
            {
               System.setProperty("webdriver.IE.driver", "C:\\Users\\Ryuk~\\Downloads\\IEDriverServer_x64_2.43.0\\IEDriverServer.exe");
               driver = new InternetExplorerDriver();
            }
         }
      }
      if(driver !null)
      {
         driver.get("https://gmail.com");
         System.out.println(driver.getTitle());
      }
   }
}

I also added a small piece of validation so as to check if the driver isn’t null (i.e. has been assigned first), before printing it.

I also hope you have a method for getTitle() otherwise there could be issues there as well.


Now,


1) That *should solve your problem.

2) I (personally) think it is easier to read.

3) I hope you’ve learnt the importance of {} s in your code.

solved Syntax error on token “else”, delete this token [closed]