How to setup and use Selenium 4 with Java
.
How to Install Java JDK on MacOS: https://youtu.be/t6ph4fJpTJI
How to Install Eclipse IDE on MacOS: https://youtu.be/LAkZRUvOcZA
1. CREATE A JAVA PROJECT ON ECLIPSE
- Create a com.neotech.selenium package
- Create a SeleniumDemo class
- Create a "drivers" folder under Selenium project (Right click on Selenium project -- New -- Folder)
2. DOWNLOAD SELENIUM 4 JAR FILES
- Go to selenium.dev -- Downloads
- Scroll down and click on Stable current Java version
- This will download Selenium JARs in a zip file
- Move the zip file to a safe folder (Documents/JarFiles)
- Unzip the file. It will create a folder selenium-java-4...
3. ADD EXTERNAL JARs TO THE CURRENT PROJECT
- Right Click on the Project -- Build Path -- Configure Build Path...
- Click on Libraries tab
- Click on Add External JARs
- Add the Selenium Libraries that are under "selenium-java-4..." folder
- Also add the Selenium Libraries that are under "selenium-java-4.../lib" folder
- Click on "Apply and Close"
4. DOWNLOAD CHROMEDRIVER AND COPY INTO THE PROJECT
- Go to selenium.dev -- Downloads
- Scroll down and click on Browsers
- Click on "documentation" under Chrome
- Download the Latest stable release: ChromeDriver 100.....
- Make sure it matches your chrome browser version (We highly suggest to update your browser to the latest version)
- Download the chromedriver zip file
- Move the zip file to a safe folder (Documents/JarFiles)
- Unzip the file. It will create a chromedriver file
- Copy and paste the chromedriver file under the "drivers" folder of current Java Project (eclipse-workspace/Selenium)
Sample code
public class SeleniumDemo {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "drivers/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.neotechacademy.com/");
String title = driver.getTitle();
System.out.println("title - " + title);
Thread.sleep(5000); // 5000 milliseconds = 5 seconds
driver.quit();
}
}
Видео How to setup and use Selenium 4 with Java автора Питоновый код
Видео How to setup and use Selenium 4 with Java автора Питоновый код
Информация
2 декабря 2023 г. 21:20:58
00:14:59
Похожие видео