I have looked through mulitple questions on here which had the answers that the selenium JARs need to be in the project dependencies for the IDE to be able to import.
However, I have checked in VScode and if I ain't missing something, all the selenium JARs are mentioned in the referenced libraries and should be therefore in the dependencies. The old method of right-clicking the project and opening the Java build path doesn't seem to work anymore.
I still get this error message that the selenium package does not exist.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class App {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "~/selenium/testing/bin/chromedriver");
System.out.println("Hello, World!");
}
}
How can this be fixed? I am using VSC on the Linux virtual machine which is by default installed on the newer chromebooks (can't get another laptop atm)
Thank you for your help.
Self-answered:
As I found out after doing a ton of research, this has nothing to do with Selenium but with a Java Extension from Visual Studio Code. For some reason, if you have the Extension "Java Language Support by George Fraser" active, importing anything from Selenium (and maybe even more frameworks) won't work. You can recognize this by the error message that says compiler.err.doesnt.exist
at the end.
For those of you reading this and having the same problem, you have two options:
Apart from that, for those of you who have been following the tutorials for setting up Selenium in Visual Studio Code using Java, the Tutorials are very outdated. If you are following the tutorial, you will always receive a NoSuchDriverException
which says that the driver has been found but it is invalid.
The way to fix this is to remove the System.setProperty("[insert webdriver here]", "[insert path to external driver here")
line, because since Selenium Version 4.6. came out, Selenium downloads the driver it needs automatically. It also has the required jar files in the Selenium library already, so you can skip the part of downloading external webdrivers like Chromedriver.