1. Setup Prerequisites
Install Java JDK (version 8 or above)
Install an IDE like Eclipse or IntelliJ
Download Selenium Java bindings from:
https://www.selenium.dev/downloads/Download the Microsoft Edge WebDriver:
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/Make sure the version of Edge WebDriver matches your Edge browser version.
2. Add WebDriver to System PATH
Place the msedgedriver.exe in a known directory (e.g., C:\WebDriver) and add that path to the system environment variable PATH.
3. Basic Selenium Java code for Edge browser
Here’s a complete example:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.edge.EdgeDriver; public class EdgeTest { public static void main(String[] args) { // Set system property (optional if msedgedriver is in PATH) System.setProperty("webdriver.edge.driver", "C:\\WebDriver\\msedgedriver.exe"); // Create instance of EdgeDriver WebDriver driver = new EdgeDriver(); // Open a website driver.get("https://www.google.com"); // Print the title of the page System.out.println("Page title is: " + driver.getTitle()); // Close browser driver.quit(); } }
4. Add Selenium Libraries to Project
In Eclipse or IntelliJ:
Right-click on project >
Build Path>Add External ArchivesAdd all JARs from Selenium zip (
selenium-java-X.X.X.zip)
5. Run the Program
Run the Java class as a Java application.
Edge browser should launch and navigate to Google.
No comments:
Post a Comment