Selenium Demo
Creating a Selenium demo involves setting up a simple Selenium WebDriver project and writing a basic test script to interact with a web page. Below, I’ll outline the steps to create a Selenium demo using Java as an example. You can adapt this for other programming languages as well.
Step 1: Set Up Your Development Environment
Install Java Development Kit (JDK): If not already installed, download and install the latest JDK from the Oracle or OpenJDK website.
Install an Integrated Development Environment (IDE): Choose an IDE for Java development, such as IntelliJ IDEA, Eclipse, or Visual Studio Code.
Set Up a Build Tool: Use a build tool like Maven or Gradle to manage dependencies and build your Selenium project. You can create a Maven or Gradle project from your IDE.
Step 2: Create a Selenium Project
- Create a new Java project in your chosen IDE and configure it as a Maven or Gradle project if you haven’t already.
Step 3: Add Selenium WebDriver Dependencies
In your project’s
pom.xml
(for Maven) orbuild.gradle
(for Gradle), add dependencies for Selenium WebDriver. Here’s an example for Maven:xml<dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> </dependencies>
Be sure to use the latest version of Selenium WebDriver.
Step 4: Create a Selenium Test Script
Create a Java class to write your Selenium test script. Here’s a simple example that opens a web page, interacts with an element, and performs a basic assertion:
javaimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class SeleniumDemo { public static void main(String[] args) { // Set the path to your ChromeDriver executable System.setProperty("webdriver.chrome.driver", "path/to/chromedriver"); // Initialize the WebDriver (in this case, Chrome) WebDriver driver = new ChromeDriver(); // Navigate to a website driver.get("https://www.example.com"); // Find an element by its CSS selector WebElement element = driver.findElement(By.cssSelector("h1")); // Perform an action (e.g., get text) String text = element.getText(); // Perform an assertion assert text.equals("Example Domain"); // Close the browser driver.quit(); } }
Make sure to replace
"path/to/chromedriver"
with the actual path to your ChromeDriver executable.
Step 5: Run the Selenium Test
- Execute your Selenium test script using your IDE’s built-in test runner or by running the Java class directly. The script will open a Chrome browser, navigate to “https://www.example.com,” and perform the specified actions and assertions.
Step 6: Review the Results
- After running the test, review the results to ensure that the Selenium script interacts correctly with the web page and that the assertions pass.
Demo Day 1 Video:
Conclusion:
Unogeeks is the No.1 IT Training Institute for Selenium Training. Anyone Disagree? Please drop in a comment
You can check out our other latest blogs on Selenium here – Selenium Blogs
You can check out our Best In Class Selenium Training Details here – Selenium Training
Follow & Connect with us:
———————————-
For Training inquiries:
Call/Whatsapp: +91 73960 33555
Mail us at: info@unogeeks.com
Our Website ➜ https://unogeeks.com
Follow us:
Instagram: https://www.instagram.com/unogeeks
Facebook:https://www.facebook.com/UnogeeksSoftwareTrainingInstitute
Twitter: https://twitter.com/unogeeks