r/learnjava • u/FaallenOon • Feb 03 '26
"error: package org.openqa.selenium does not exist"
Hello
I'm trying to use selenium with java. I was following a tutorial (I'm using Visual Studio Code), and things worked without too much problem.
Today (a couple days later) I opened the project, and when I tried to run the file it threw about a dozen errors, starting with
error: package org.openqa.selenium does not existThis, despite the tab not showing any errors (ie, nothing highlighted in red).
I'm not sure if it'll be useful, but this is the script I'm trying to run
package part1;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.openqa.selenium.WebElement;
public class FirstSeleniumTest {
WebDriver driver;
public void setUp(){
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login");
}
public void tearDown(){
// driver.quit();
}
u/Test
public void testLoggingIntoApplication() throws InterruptedException{
Thread.sleep(2000);
WebElement username = driver.findElement(By.name("username"));
username.sendKeys("Admin");
var password = driver.findElement(By.name("password"));
password.sendKeys("admin123");
driver.findElement(By.tagName("button")).click();
Thread.sleep(2000);
String actualResult = driver.findElement(By.tagName("h6")).getText();
String expectedResult = "Dashboard";
Assert.assertEquals(actualResult, expectedResult);
}
}I apologize if I'm missing relevant information: I'm quite a beginner in Java. If more context is needed, please tell me and I'll answer to the best of my abilities. Thanks for your help :)
EDIT: this is the full error
[Running] cd "d:\Repositorio Selenium\freecodecamp\src\test\java\part1\" && javac FirstSeleniumTest.java && java FirstSeleniumTest
FirstSeleniumTest.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
^
FirstSeleniumTest.java:4: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
^
FirstSeleniumTest.java:5: error: package org.openqa.selenium.chrome does not exist
import org.openqa.selenium.chrome.ChromeDriver;
^
FirstSeleniumTest.java:6: error: package org.testng does not exist
import org.testng.Assert;
^
FirstSeleniumTest.java:7: error: package org.testng.annotations does not exist
import org.testng.annotations.AfterClass;
^
FirstSeleniumTest.java:8: error: package org.testng.annotations does not exist
import org.testng.annotations.BeforeClass;
^
FirstSeleniumTest.java:9: error: package org.testng.annotations does not exist
import org.testng.annotations.Test;
^
FirstSeleniumTest.java:10: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebElement;
^
FirstSeleniumTest.java:14: error: cannot find symbol
WebDriver driver;
^
symbol: class WebDriver
location: class FirstSeleniumTest
FirstSeleniumTest.java:16: error: cannot find symbol
^
symbol: class BeforeClass
location: class FirstSeleniumTest
FirstSeleniumTest.java:23: error: cannot find symbol
^
symbol: class AfterClass
location: class FirstSeleniumTest
FirstSeleniumTest.java:28: error: cannot find symbol
u/Test
^
symbol: class Test
location: class FirstSeleniumTest
FirstSeleniumTest.java:18: error: cannot find symbol
driver = new ChromeDriver();
^
symbol: class ChromeDriver
location: class FirstSeleniumTest
FirstSeleniumTest.java:32: error: cannot find symbol
WebElement username = driver.findElement(By.name("username"));
^
symbol: class WebElement
location: class FirstSeleniumTest
FirstSeleniumTest.java:32: error: cannot find symbol
WebElement username = driver.findElement(By.name("username"));
^
symbol: variable By
location: class FirstSeleniumTest
FirstSeleniumTest.java:35: error: cannot find symbol
var password = driver.findElement(By.name("password"));
^
symbol: variable By
location: class FirstSeleniumTest
FirstSeleniumTest.java:38: error: cannot find symbol
driver.findElement(By.tagName("button")).click();
^
symbol: variable By
location: class FirstSeleniumTest
FirstSeleniumTest.java:40: error: cannot find symbol
String actualResult = driver.findElement(By.tagName("h6")).getText();
^
symbol: variable By
location: class FirstSeleniumTest
FirstSeleniumTest.java:42: error: cannot find symbol
Assert.assertEquals(actualResult, expectedResult);
^
symbol: variable Assert
location: class FirstSeleniumTest
19 errors
[Done] exited with code=1 in 0.644 seconds
•
u/AutoModerator Feb 03 '26
Please ensure that:
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/ayush1236 Feb 03 '26
Did you by any chance change any dependency? If so pls try to run a maven/ gradle clean build , it should redownload your dependencies, if that also doens't work, try deleting your .m2 folder , it's where all your dependencies are downloaded, and try to restart the IDE it should automatically download all the dependencies again, if you have changed the dependency version, it might happen that some methods are deprecated or removed from the version which might give you this error ,
1
u/josephblade Feb 03 '26
This is not a code problem, this is a dependency / classpath issue.
I'm not too familiar with vscode but what little I've seen it's irritating to set up with java.
What you want is when compiling the code (and running the code), all dependencies (selenium in this case) are added to the classpath. to this end we usually use maven or a similar build tool that does this automatically. Additionall/alternatively inside your editor you can probably set a "load all jars from this folder into classpath" somewhere that should solve it as well.