
- Selenium - Home
- Selenium - Overview
- Selenium - Components
- Selenium - Automation Testing
- Selenium - Environment Setup
- Selenium - Remote Control
- Selenium - IDE Introduction
- Selenium - Features
- Selenium - Limitations
- Selenium - Installation
- Selenium - Creating Tests
- Selenium - Creating Script
- Selenium - Control Flow
- Selenium - Store Variables
- Selenium - Alerts & Popups
- Selenium - Selenese Commands
- Selenium - Actions Commands
- Selenium - Accessors Commands
- Selenium - Assertions Commands
- Selenium - Assert/Verify Methods
- Selenium - Locating Strategies
- Selenium - Script Debugging
- Selenium - Verification Points
- Selenium - Pattern Matching
- Selenium - JSON Data File
- Selenium - Browser Execution
- Selenium - User Extensions
- Selenium - Code Export
- Selenium - Emitting Code
- Selenium - JavaScript Functions
- Selenium - Plugins
- Selenium WebDriver Tutorial
- Selenium - Introduction
- Selenium WebDriver vs RC
- Selenium - Installation
- Selenium - First Test Script
- Selenium - Driver Sessions
- Selenium - Browser Options
- Selenium - Chrome Options
- Selenium - Edge Options
- Selenium - Firefox Options
- Selenium - Safari Options
- Selenium - Double Click
- Selenium - Right Click
- HTML Report in Python
- Handling Edit Boxes
- Selenium - Single Elements
- Selenium - Multiple Elements
- Selenium Web Elements
- Selenium - File Upload
- Selenium - Locator Strategies
- Selenium - Relative Locators
- Selenium - Finders
- Selenium - Find All Links
- Selenium - User Interactions
- Selenium - WebElement Commands
- Selenium - Browser Interactions
- Selenium - Browser Commands
- Selenium - Browser Navigation
- Selenium - Alerts & Popups
- Selenium - Handling Forms
- Selenium - Windows and Tabs
- Selenium - Handling Links
- Selenium - Input Boxes
- Selenium - Radio Button
- Selenium - Checkboxes
- Selenium - Dropdown Box
- Selenium - Handling IFrames
- Selenium - Handling Cookies
- Selenium - Date Time Picker
- Selenium - Dynamic Web Tables
- Selenium - Actions Class
- Selenium - Action Class
- Selenium - Keyboard Events
- Selenium - Key Up/Down
- Selenium - Copy and Paste
- Selenium - Handle Special Keys
- Selenium - Mouse Events
- Selenium - Drag and Drop
- Selenium - Pen Events
- Selenium - Scroll Operations
- Selenium - Waiting Strategies
- Selenium - Explicit/Implicit Wait
- Selenium - Support Features
- Selenium - Multi Select
- Selenium - Wait Support
- Selenium - Select Support
- Selenium - Color Support
- Selenium - ThreadGuard
- Selenium - Errors & Logging
- Selenium - Exception Handling
- Selenium - Miscellaneous
- Selenium - Handling Ajax Calls
- Selenium - JSON Data File
- Selenium - CSV Data File
- Selenium - Excel Data File
- Selenium - Cross Browser Testing
- Selenium - Multi Browser Testing
- Selenium - Multi Windows Testing
- Selenium - JavaScript Executor
- Selenium - Headless Execution
- Selenium - Capture Screenshots
- Selenium - Capture Videos
- Selenium - Page Object Model
- Selenium - Page Factory
- Selenium - Record & Playback
- Selenium - Frameworks
- Selenium - Browsing Context
- Selenium - DevTools
- Selenium Grid Tutorial
- Selenium - Overview
- Selenium - Architecture
- Selenium - Components
- Selenium - Configuration
- Selenium - Create Test Script
- Selenium - Test Execution
- Selenium - Endpoints
- Selenium - Customizing a Node
- Selenium Reporting Tools
- Selenium - Reporting Tools
- Selenium - TestNG
- Selenium - JUnit
- Selenium - Allure
- Selenium & other Technologies
- Selenium - Java Tutorial
- Selenium - Python Tutorial
- Selenium - C# Tutorial
- Selenium - Javascript Tutorial
- Selenium - Kotlin Tutorial
- Selenium - Ruby Tutorial
- Selenium - Maven & Jenkins
- Selenium - Database Testing
- Selenium - LogExpert Logging
- Selenium - Log4j Logging
- Selenium - Robot Framework
- Selenium - AutoIT
- Selenium - Flash Testing
- Selenium - Apache Ant
- Selenium - Github Tutorial
- Selenium - SoapUI
- Selenium - Cucumber
- Selenium - IntelliJ
- Selenium - XPath
- Selenium Miscellaneous Concepts
- Selenium - IE Driver
- Selenium - Automation Frameworks
- Selenium - Keyword Driven Framework
- Selenium - Data Driven Framework
- Selenium - Hybrid Driven Framework
- Selenium - SSL Certificate Error
- Selenium - Alternatives
Selenium WebDriver - First Test Script
Before starting with our first test script on Selenium, we should ensure that Java, and Maven have been installed in our system.
Prerequisites Steps To Create the First Test Script
Step 1 − Confirm Java installation by running the command: java, from the command prompt.
Step 2 − Confirm the version of the Java installed by running the command:
java version
Step 3 − Confirm the version of the Maven installed by running the command −
mvn version
Step 4 − Download and install any code editor, say the Eclipse from the link Download Eclipse Technology.
To get more information about the Eclipse and its installation process, please visit the link Eclipse Tutorial.
Steps To Create the First Test Script
Step 1 − Initiate a driver session and perform some activity on the browser, say launching an web page on the Chrome browser with the help of the below code −
Webdriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/selenium/practice/text-box.php");
Step 2 − Retrieve some information about the current URL that is launched on the Chrome browser with the help of the getCurrentUrl() method.
driver.getCurrentUrl();
Step 3 − Add some synchronization techniques so that the interactions between the Selenium tool and browser actions would be in sync. There are several synchronization methods available in Selenium, like the implicit, explicit, and fluent waits.
While implicit wait is a kind of global wait (applicable to all the steps in a text case), explicit and fluent waits are applied to a specific element on the browser. For our first test script here, we would only apply an implicit wait.
Syntax to add an implicit wait of 15 seconds −
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
To get more information about the different waits in Selenium, please visit the link Selenium Webdriver Wait Support.
Step 4 − Perform any task on a webelement in the same webdriver session, for that purpose, identify the element uniquely with the help of any of the Selenium Locators like id, name, class, tagname, link text, partial link text, xpath, and css selector along with findElement() method. If there are multiple elements with the same value of locator, only the first matching element should be identified.
Syntax to identify an element with xpath locator −
WebElement e = driver.findElement(By.xpath("<value of xpath>"));
Step 5 − Perform a task on the element identified on the previous step using the sendKeys() method. Enter the text - Selenium and text to be entered is passed as an argument to the method.
Syntax
e.sendKeys("Selenium");
Step 6 − Request the information on the value entered on input box using the getAttribute() method and value is passed as an argument to the method.
Syntax
String text = driver.findElement(By.xpath("<value of xpath>")).getAttribute("value");
Step 7 − Wipe out the text entered with the clear() method.
Syntax
e.clear();
Step 8 − Again request the information on the value on the input box using the getAttribute() method(to prove there is no value within the input box after using the clear() method) and value is passed as an argument to the method.
Syntax
String text = driver.findElement(By.xpath("<value of xpath>")).getAttribute("value");
Step 9 − Terminate the driver session using the quit() method which would also close the opened browser window.
Syntax
driver.quit();
Example
Right click on the web page below, and then click on the Inspect button in the Chrome browser. For identifying the first text box on the page, click on the left upward arrow at the top of the visible HTML code as highlighted below.

Once we had clicked and pointed the arrow to the input box(highlighted in the below image), its HTML code appeared, reflecting the input tagname and the type attribute having the value as text.

Let us take an example of the above page, where we would first input text in the text box with the help of the sendKeys() method. Later, we would clear out the text with the help of the clear() method.
Code Implementation
package org.example; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class FrstJavaTestScript { public static void main(String[] args) throws InterruptedException { // Initiate the Webdriver WebDriver driver = new ChromeDriver(); // adding implicit wait of 15 secs driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); // Opening the webpage where we will identify edit box to enter driver.get("https://www.tutorialspoint.com/selenium/practice/text-box.php"); // getting current URL System.out.println("Getting the Current URL: " + driver.getCurrentUrl()); // Identify the input box with xpath locator WebElement e = driver.findElement(By.xpath("//*[@id='fullname']")); // enter text in input box e.sendKeys("First Test Script"); // Get the value entered String text = e.getAttribute("value"); System.out.println("Entered text is: " + text); // clear the text entered e.clear(); // Get no text after clearing text String text1 = e.getAttribute("value"); System.out.println("Get text after clearing: " + text1); // Closing browser driver.quit(); } }
Output
Getting the Current URL: https://www.tutorialspoint.com/selenium/practice/text-box.php Entered text is: First Test Script Get text after clearing: Process finished with exit code 0
In the above example, we had first obtained the current URL with the message in the console: Getting the Current URL: Selenium Automation Practice Form . Then we had entered the text First Test Script in the input box, We had retrieved the value entered in the console with the message - Entered text is: First Test Script. Next, we had cleared the value entered, and hence, obtained no value in the same text box.
Finally, the message Process finished with exit code 0 was received, signifying successful execution of the code.
Conclusion
This concludes our comprehensive take on the tutorial on Selenium Webdriver First Test Script. Weve started with describing prerequisite steps to create the First Test Script, steps to create the First Test Script, and an example to illustrate how to create the first test script in Selenium Webdriver. This equips you with in-depth knowledge of the Selenium Webdriver - First Test Script. It is wise to keep practicing what youve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.