Selenium WebDriver Setup and Basic Methods

This section we are going to add Selenium WebDriver and Cucumber Junit, Selenium WebDriver will operate web browser remotely by calling WebDriver API. For this tutorial we are going to use Chrome WebDriver, Please see the article about Selenium WebDriver Configuration for more clarification.

Step by Step process of Selenium dependencies add to gradle

  • From you projects find the file called build.gradle

  • There will a block which we added last time called dependencies, find the closure.

  • Add the below dependencies into that closure.

    testImplementation 'io.cucumber:cucumber-junit:5.6.0'
    implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
    implementation 'org.seleniumhq.selenium:selenium-chrome-driver:3.141.59'

Here 1st dependency for Cucumber Junit, rest are for Selenium.

  • After add those dependencies the dependency closure will be like below


    project.ext {
        cucumberVersion = '5.6.0'

    dependencies {
        testImplementation 'io.cucumber:cucumber-java:' + cucumberVersion
        testImplementation 'io.cucumber:cucumber-junit:5.6.0'
        implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
        implementation 'org.seleniumhq.selenium:selenium-chrome-driver:3.141.59'


Below methods will use in project

Selenium WebDriver comes with lots of features and control method, we are not gonna discuss all of them, here I listed some methods which will need to use in our current project. Let’s see them.

  1. webDriver.manage().window().maximize(): This method responsible for maximize the browser window.

  2. webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS): It’s command browser to wait for certain amount of time.

  3. webDriver.get(url): Load the url into browser.

  4. webDriver.close(): Closes the current browser associated with the driver.

  5. webDriver.quit(): Shutdown the opened browser.

  6. webDriver.findElement(By.className("some-class")): It’s allowed to find and select the element by class name.

  7. webElement.sendKeys("some-text"): Put value into input box.

  8. Trigger click action to element.

  9. webElement.getText(): Bring values from elements.

YouTube Video Tutorial of Setup Selenium WebDriver & Basic