Tumgik
tkxell · 7 months
Text
Selenium WebDriver is a popular open-source web automation framework. It allows you to control a web browser from within your test scripts, making it easy to automate tasks such as navigating to web pages, entering text, clicking buttons, and selecting options from drop-down menus.
Setting Up Selenium
To set up Selenium, you will need to install the following:
A programming language (e.g., Java, Python, C#, or JavaScript)
The Selenium WebDriver bindings for your chosen programming language
Web browser drivers for the browsers you want to automate
You can download the Selenium WebDriver bindings and web browser drivers from the Selenium website.
Once you have installed the necessary software, you need to configure Selenium. This involves setting the following environment variables:
SELENIUM_WEBDRIVER_CHROME_DRIVER_PATH (if using Chrome)
SELENIUM_WEBDRIVER_GECKO_DRIVER_PATH (if using Firefox)
SELENIUM_WEBDRIVER_EDGE_DRIVER_PATH (if using Edge)
SELENIUM_WEBDRIVER_SAFARI_DRIVER_PATH (if using Safari)
You can set these environment variables in your operating system's environment settings or in your IDE.
Writing Your First Selenium Test
Once you have configured Selenium, you can start writing your first Selenium test. Here is a simple example in Java:
Java
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class MyFirstSeleniumTest { public static void main(String[] args) { // Create a WebDriver instance WebDriver driver = new ChromeDriver(); // Navigate to Google driver.get("https://www.google.com"); // Find the search bar WebElement searchBar = driver.findElementById("q"); // Enter the search term "Selenium" searchBar.sendKeys("Selenium"); // Click the search button searchBar.submit(); // Wait for the search results page to load driver.wait(1000); // Print the title of the search results page System.out.println(driver.getTitle()); // Close the browser driver.quit(); } }
To run this test, simply compile it and run the main class. Selenium will start a Chrome browser, navigate to Google, enter the search term "Selenium", click the search button, wait for the search results page to load, and print the title of the search results page.
1 note · View note