0

I'm new to selenium. I installed all the required Jars, but at the end when I run the script to see if it works, I got an error message. Please help.

Code:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    public class Demo {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            //selenium code
                    
                    //create Driver object for Chrome Browser
                    
                    //We will strictly implement methods of webdriver
                    
                        /* Class name= x
                                x driver=new x();*/
                    
            //Invoke.exe File first
                    System.setProperty("webdriver.chrome.driver", "C:\\Users\\mezia\\Documents.exe");
                    WebDriver driver = new ChromeDriver();
                    driver.get("http:\\google.com");

Error:

Exception in thread "main" java.lang.Error: Unresolved compilation
problems: 
        WebDriver cannot be resolved to a type
        ChromeDriver cannot be resolved to a type
        WebDriver cannot be resolved to a type
        FirefoxDriver cannot be resolved to a type
        Syntax error, insert ";" to complete Statement 
        at Demo.main(Demo.java:12)
  • Please share the exact code. It shows syntax error you are missing } after driver.get also ensure that you are using proper chromedriver from this link chromedriver.chromium.org/downloads – Mohamed Sulaimaan Sheriff Mar 30 at 3:36
  • Hi Mohamed, Thank you for your reply to my inquiry. I wrote exactly what you mentioned but I'm still having issues. 1- I added the latest version of the chrome driver and I extracted all. I moved the file to my documents. I tried to open the file and I get a blue window error message. 2- I put my mousse on both Chrome Driver and WebDriver to correct the error as the red line appears on both of them but still shows a syntax error – Meziane Hammiche Mar 30 at 16:16
0

What is Documents.exe? It looks like you set the chrome driver path to that file but that doesn't look like the chrome driver. You will have to download the latest chrome driver from here: https://chromedriver.chromium.org/downloads and then set your path to the chrome.exe that is downloaded from there.

Once you have the driver downloaded, move it to any folder you would like. To keep it simple I would put it in your Documents folder. Once it is there this is what your code should look like.

System.setProperty("webdriver.chrome.driver", "C:\\Users\\mezia\\Documents\\chrome.exe");
| improve this answer | |
  • Hi Eric, Thank you for your reply to my inquiry. I wrote exactly what you mentioned but I'm still having issues. 1- I added the latest version of the chrome driver and I extracted all. I moved the file to my documents. I tried to open the file and I get a blue window error message. 2- I put my mousse on both Chrome Driver and WebDriver to correct the error as the red line appears on both of them but still shows a syntax error Please see pictures attached – Meziane Hammiche Mar 30 at 16:14
  • The chrome driver does not need to be opened or executed. It just needs to be saved in a folder where Selenium can access it. The System.setProperty is how you tell Selenium where to look. You mentioned a red line under WebDriver. This leads me to believe that you may have downloaded the selenium jars but your IDE (eclipse, intellij, etc.) is not recognizing it. I'm not sure if you have already done this step but you may need to add the jars to your project path. I would search youtube on how to do this. – Eric Mar 30 at 22:15
  • Thank you for your help. I managed to solve the issue in a different way – Meziane Hammiche Mar 31 at 16:57
  • What was the solution? – Eric Mar 31 at 17:04
  • I removed the selenium java jar files from Modulepath and added to Classpath – Meziane Hammiche Apr 1 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.