Selenium Demo
Creating a demo test case with Selenium typically involves writing a simple script to automate a web browser and interact with web elements. For this demonstration, I’ll outline a basic Selenium WebDriver script in Python. The example will demonstrate opening a web browser (Chrome, in this case), navigating to a website (e.g., Google), performing a search, and then closing the browser.
Prerequisites
- Python Installation: Ensure Python is installed on your system.
- Selenium Installation: Install Selenium WebDriver for Python using pip:bash
pip install selenium
- WebDriver Installation: Download the ChromeDriver from its website. Ensure it’s placed in a directory that’s in your system’s PATH, or provide the path in your script.
Selenium WebDriver Demo Script
Here’s a simple script that demonstrates basic Selenium WebDriver functionality:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Set up WebDriver
driver = webdriver.Chrome() # or specify the path if not in PATH
# Navigate to a URL
driver.get("http://www.google.com")
# Find an element and interact with it
search_box = driver.find_element_by_name('q') # Locate the Google search box
search_box.send_keys('Selenium WebDriver') # Input text into the search box
search_box.send_keys(Keys.RETURN) # Simulate hitting the Enter key
# Wait to see the results
driver.implicitly_wait(10) # Waits for 10 seconds
# Close the browser
driver.quit()
Running the Script
- Save this script in a
.py
file, for example,selenium_demo.py
. - Run the script from the command line or your IDE.bash
python selenium_demo.py
- The script will open Chrome, navigate to Google, perform a search for “Selenium WebDriver”, and then close the browser after a brief wait.
Explanation of Key Steps
- WebDriver Setup: Initializes the WebDriver for Chrome.
- Navigation: The
driver.get
method navigates to a specified URL. - Element Interaction: Locates the search box, inputs text, and submits the form.
- Implicit Wait: Waits for elements to load.
- Closing Browser: The
driver.quit
method closes the browser window.
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