
- 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 with Kotlin Tutorial
Selenium can be used with multiple languages like Java, Python, Kotlin, JavaScript, Ruby, and so on. Selenium is used extensively for web automation testing. Selenium is an open-source and a portable automated software testing tool for testing web applications. It has capabilities to operate across different browsers and operating systems. Selenium is not just a single tool but a set of tools that helps testers to automate web-based applications more efficiently.
Setup Selenium with Kotlin
Step 1 − Install Maven in our system using the link − https://maven.apache.org/download.cgi.
To get a more detailed view on how set up Maven, refer to the link − Maven Environment.
Confirm the version of the Maven installed by running the following command −
mvn version
It will show the following output −
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) Maven home: /opt/homebrew/Cellar/maven/3.9.6/libexec Java version: 21.0.1, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home Default locale: en_IN, platform encoding: UTF-8 OS name: "mac os x", version: "14.0", arch: "aarch64", family: "mac"
The output of the command executed signified that the Maven version installed in the system is Apache Maven 3.9.6.
Step 2 − Download and install the code editor IntelliJ from the link to write and run the Selenium test − https://www.jetbrains.com/idea/.
To get a more detailed view on how set up IntelliJ, refer to the link − Selenium IntelliJ.
Step 3 − Launch IntelliJ and click on the New Project button.

Step 4 − Enter the Project Name, Location, and then select the the Language as Kotlin and Maven as the Build Systems.

Step 5 − Build the project from the Build menu.

Step 6 − Add the Selenium Maven dependencies from the link − https://mvnrepository.com/artifact/.
Step 7 − Save the pom.xml with all the dependencies and update the maven project.
Step 8 − Within the Maven project SeleniumKotlin, right click on the kotlin folder within the test folder, and create a package, say TestCases.
Step 9 − Right click on the TestCases package, and select the New menu, then click on the Kotlin Class/File menu.

Step 10 − Enter a filename, say MyTest within the New Kotlin Class/File field and press Enter.

Step 11 − Add the below code in the MyTest.kt file.
package TestCases import org.openqa.selenium.WebDriver import org.openqa.selenium.edge.EdgeDriver import java.time.Duration import org.testng.annotations.Test class MyTest { @Test fun launchBrow() { // Initiate Webdriver val driver: WebDriver = EdgeDriver(); // adding implicit wait of 15 seconds driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15)); // URL launch driver.get("https://www.tutorialspoint.com/selenium/practice/selenium_automation_practice.php"); // get browser title after browser launch System.out.println("Browser title: " + driver.title); } }
Overall dependencies added in the pom.xml file −
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>SeleniumKotlin</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <kotlin.code.style>official</kotlin.code.style> <kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget> </properties> <repositories> <repository> <id>mavenCentral</id> <url>https://repo1.maven.org/maven2/</url> </repository> </repositories> <build> <sourceDirectory>src/main/kotlin</sourceDirectory> <testSourceDirectory>src/test/kotlin</testSourceDirectory> <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>1.9.23</version> <executions> <execution> <id>compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>test-compile</id> <phase>test-compile</phase> <goals> <goal>test-compile</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>2.22.2</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.6.0</version> <configuration> <mainClass>MainKt</mainClass> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-test-junit5</artifactId> <version>1.9.23</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.19.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.testng/testng --> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.10.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib</artifactId> <version>1.9.23</version> </dependency> </dependencies> </project>
Project Structure followed in this example −

Step 12 − Right click and select Run MyRun option. Wait till the run is completed.
It will show the following output −
Browser title: Selenium Practice - Student Registration Form =============================================== Default Suite Total tests run: 1, Passes: 1, Failures: 0, Skips: 0 =============================================== Process finished with exit code 0
In the above example, we had first launched the Edge browser and launched an application then retrieved the browser title and in the console received the message - Browser title: Selenium Practice - Student Registration Form.
The result in the console shows Total tests run: 1, as there is one method with @Test annotations - launchBrow().
Finally, the message Passes: 1 and Process finished with exit code 0 was received, signifying successful execution of the code.
Identify Element and Check Its Functionality Using Selenium Kotlin
Once we navigate to a webpage, we have to interact with the web elements available on the page like clicking a link/button, entering text within an edit box, and so on to complete our automation test case.
For this, our first job should be to identify the element. We can use the link text for a link for its identification and utilize the method findElement(By.linkText("<value of link text>")). With this, the first element with the matching value of the link text should be returned.
In case there is no element with the matching value of the link text, NoSuchElementException should be thrown.
Let us see the html code of the link as discussed before in the below image −

<a href="javascript:void(0)" id="moved" onclick="shide('move')">Moved</a>
The link - Moved highlighted in the above image has the link text value as Moved. Let us click on it after identifying it. The text - Link has responded with status 301 and status text Moved Permanently would appear on the web page on clicking the Moved link. Finally we would quit the browser.

Example
package TestCases import org.openqa.selenium.By import org.openqa.selenium.WebDriver import org.openqa.selenium.edge.EdgeDriver import java.time.Duration import org.testng.annotations.Test class MyTest { @Test fun accessLnkGetText() { // Initiate Webdriver val driver: WebDriver = EdgeDriver(); // adding implicit wait of 15 seconds driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15)); // URL launch driver.get("https://www.tutorialspoint.com/selenium/practice/links.php"); // identify link then click val lnk = driver.findElement(By.linkText("Moved")); lnk.click(); // identify text the get text val txt = driver.findElement(By.xpath("/html/body/main/div/div/div[2]/div[3]")); System.out.println("Text Obtained is: " + txt.text); // quit browser driver.quit() } }
It will show the following output −
Text Obtained is: Link has responded with status 301 and status text Moved Permanently =============================================== Default Suite Total tests run: 1, Passes: 1, Failures: 0, Skips: 0 =============================================== Process finished with exit code 0
In the above example, we had first launched the Edge browser and launched an application then clicked on the link. After clicking the link, we had obtained the text and in the console received the message - Text Obtained is: Link has responded with status 301 and status text Moved Permanently.
The result in the console shows Total tests run: 1, as there is one method with @Test annotations - accessLnkGetText().
Finally, the message Passes: 1 and Process finished with exit code 0 was received, signifying successful execution of the code.
This concludes our comprehensive take on the tutorial on Selenium - Kotlin Tutorial. Weve started with describing how to set up Selenium with Kotlin, how to launch a browser and quit a session using the Selenium Kotlin, and how to identify an element and check its functionality using Selenium Kotlin.
This equips you with in-depth knowledge of the Selenium - Kotlin Tutorial. It is wise to keep practicing what youve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.