I'm doing exactly what the website says but it results in 4 errors...

- 183,867
- 41
- 278
- 352

- 406
- 1
- 8
- 24
-
I'm not a Java Person, but are you missing any imports in your code? – Satish May 31 '18 at 21:15
-
He is. Use the magic keys Ctrl+Shift+o – Ji aSH May 31 '18 at 21:28
-
And please rename the `Chrome.java` to `ChromeTest.java` – yong May 31 '18 at 23:48
-
Please read why [a screenshot of code is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. – JeffC Jun 01 '18 at 02:07
2 Answers
There are exactly 4 errors as follows:
Error: ChromeDriver cannot be resolved to a type
Solution: You need to add the following import
import org.openqa.selenium.chrome.ChromeDriver;
- Here you can find a discussion on chrome Webdriver can't be resolved to a type error eclipse and java
Error: Test cannot be resolved to a type
Solution: You need to add the following import
import org.testng.annotations.Test; //or import org.junit.Test;
Error: The public type ChromeTest must be defined in its own file
Solution: Your filename is Chrom.java but your classname is ChromeTest where as both should have been similar. Change them as identical.
Here you can find a discussion on “The public type must be defined in its own file” but the file name and the class name is the same
Error: WebDriver cannot be resolved to a type
Solution: You need to add the following import
import org.openqa.selenium.WebDriver;
Best Practice
- You have to keep the filename (currently Chrom.java) and your classname (currently ChromeTest) identical as a mandatory measure.
- You need to mention the related imports whenever you are using any class. You can Mouse Hover over the error and choose the relevant import.
- You should either add the testng jars or the junit jars but not both of them.

- 183,867
- 41
- 278
- 352
From your code, i didn't see any imports and class name was different from filename(As @yong mentioned in his comment).
Your Java file name should always reflect the public class defined within that file. Otherwise, you will get a compiler error.
Modify your code like this : (you had a typo, firstPackage)
package firstPackage;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeTest {
@Test
public void LaunchChrome_method(){
System.setProperty("webdriver.chrome.driver","D:\\Drivers\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("http://www.google.com");
}
}
-
The website did not mention it. http://www.automationtestinghub.com/selenium-chromedriver/ – tijnn Jun 01 '18 at 10:08
-
-
-
junit was not in my package explorer list. I added it and then the error message was gone... – tijnn Jun 01 '18 at 10:31