Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Tech Solutions
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Selenium Automation Testing

  • Introduction to Automation Testing
  •  Introduction to Selenium
  • Advantages and Disadvantages of Selenium WebDriver
  •  Locators in Selenium
  • How to launch the browsers ? 
  • Browser Navigation Commands in Selenium
  •  Handling the textbox and button using selenium
  • Handling the radio button and checkbox using selenium
  •  Handling the drop downs and multi-select dropdown
  • Validate the text validation and attributes values. 
  • Handling Alert Popup
  • Handling iFrames
  • Handling Multiple Browsers or Tabs
View Categories
  • Home
  • Tutorials
  • Selenium Automation
  • Selenium Automation Testing
  •  Handling the textbox and button using selenium

 Handling the textbox and button using selenium

 Handling the textbox and

button using selenium

Handling of Text box 

Test Case Flow: 

  1. Launches Chrome
  2. Navigates to a demo page
  3. Locates a text box via an XPath locator
  4. Checks if it’s enabled
  5. Enters text, pauses, then clears it
  6. Closes the browser

Program:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

public class TextBoxExample {

    public static void main(String[] args) throws InterruptedException {

        // 1. Point to your ChromeDriver executable

        System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

        // 2. Launch Chrome

        WebDriver driver = new ChromeDriver();

        try {

            // 3. Navigate to the page containing your text box

            driver.get("https://example.com/login");  

            // 4. Locate the text box using an XPath locator

            //    (adjust the XPath to match your page)

            WebElement usernameField = driver.findElement(

                By.xpath("//input[@id='username']"));

            // 5. Check if the element is enabled

            boolean isEnabled = usernameField.isEnabled();

            System.out.println("Username field enabled? " + isEnabled);

            if (isEnabled) {

                // 6. Enter some text

                usernameField.sendKeys("myTestUser");

                // (just for demo) wait so you can see it happen

                Thread.sleep(2000);

                // 7. Clear the text

                usernameField.clear();

                Thread.sleep(1000);

            }

        } finally {

            // 8. Close the browser (and end the session)

            driver.quit();

        }

    }

}

Notes:

  • Replace “/path/to/chromedriver” with the actual path on your machine (or use WebDriverManager).
  • Adjust the URL (https://example.com/login) and the XPath (//input[@id=’username’]) to match your application under test.
  • The Thread.sleep(…) calls are only for demonstration—typically you’d use explicit waits instead.

Handling of Button 

Test Case Flow: 

  1. Setup & launch – points to your local chromedriver, then opens a new Chrome window.
  2. Navigate – goes to the URL where your button lives.
  3. Locate – finds the <button> via an XPath (change //button[@id=’submit’] to suit your page).
  4. Verify – prints out whether the button is visible on the page and enabled for clicking.
  5. Click – only clicks if both checks pass.
  6. Verify result – you can inspect the current URL or page title to ensure the click did what you expected.
  7. Teardown – quits the driver, closing all browser windows.

Program:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

public class ButtonExample {

    public static void main(String[] args) throws InterruptedException {

        // 1. Point to your ChromeDriver executable

        System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

        // 2. Launch Chrome

        WebDriver driver = new ChromeDriver();

        try {

            // 3. Navigate to the page containing your button

            driver.get("https://example.com");  

            // 4. Locate the button using an XPath locator

            //    (adjust the XPath to match your page)

            WebElement submitBtn = driver.findElement(

                By.xpath("//button[@id='submit']"));

            // 5. Check if the button is displayed and enabled

            System.out.println("Button displayed? " + submitBtn.isDisplayed());

            System.out.println("Button enabled?   " + submitBtn.isEnabled());

            // 6. Click the button if possible

            if (submitBtn.isDisplayed() && submitBtn.isEnabled()) {

                submitBtn.click();

                // 7. (Optional) Pause so you can see the result

                Thread.sleep(2000);

                // 8. (Optional) Verify navigation or change

                System.out.println("Current URL after click: " + driver.getCurrentUrl());

            }

        } finally {

            // 9. Close the browser (and end the session)

            driver.quit();

        }

    }

}
Selenium Automation Testing
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
Browser Navigation Commands in SeleniumHandling the radio button and checkbox using selenium
© 2018 – 2025 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105