Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothtechsolutions@gmail.com
Vinoth Tech Solutions
  • Home
  • Tutorials
  • End-to-End QA Projects
    • API Manual and Automation Testing using SoapUI
    • DevOps CI CD using Real Time Project Setup
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • About Me & Feedback
    • LinkedIn Profile
    • Placed Students Feedback
    • Online Training Feedback
    • TechTalk
  • FAQS
  • Demo Sites
    • Practice Automation
      • Registration Form
      • Transaction Details
      • DropDown
      • Basic Authentication
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
      • Date Picker Calendar
    • E-Commerce Demo Application
    • Healthcare Demo Page
    • Create Account Demo Page
    • Python JS Online Compiler
  • Home
  • Tutorials
  • End-to-End QA Projects
    • API Manual and Automation Testing using SoapUI
    • DevOps CI CD using Real Time Project Setup
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • About Me & Feedback
    • LinkedIn Profile
    • Placed Students Feedback
    • Online Training Feedback
    • TechTalk
  • FAQS
  • Demo Sites
    • Practice Automation
      • Registration Form
      • Transaction Details
      • DropDown
      • Basic Authentication
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
      • Date Picker Calendar
    • E-Commerce Demo Application
    • Healthcare Demo Page
    • Create Account Demo Page
    • Python JS Online Compiler

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 Images
  • Handling Mouse Events
  • Handling Keyboard Events
  • Handling Alert Popup
  • Handling iFrames
  • Handling Multiple Browsers or Tabs
  • Types of wait statement in selenium
  • How to take screenshots?
  • How to upload File in Selenium?
  • How to handle scroll function using JavaScriptExecutor?
  • How to handle basic functionality using JavaScriptExecutor?
  • How to handle advanced functionality using JavaScriptExecutor?
  • How to automate CAPTCHA?
  • How to handle cookies in selenium
View Categories
  • Home
  • Tutorials
  • Selenium Automation
  • Selenium Automation Testing
  • How to handle basic functionality using JavaScriptExecutor?

How to handle basic functionality using JavaScriptExecutor?

How to handle basic functionality

using JavaScriptExecutor?

We can use JavaScriptExecutor in Selenium to interact with elements such as text boxes, checkboxes, radio buttons, dropdowns, and buttons, especially when standard Selenium methods (.click(), .sendKeys(), etc.) do not work due to JavaScript frameworks, hidden elements, or overlays.

Below are JavaScriptExecutor code examples for each type in Java:

1. Text Box: Set Value

📄
filename.js
WebElement textBox = driver.findElement(By.id("username"));

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("arguments[0].value='VinothQA';", textBox);

2. Checkbox: Check/Uncheck

Check the Checkbox

📄
filename.js
WebElement checkbox = driver.findElement(By.id("acceptTerms"));

js.executeScript("arguments[0].checked=true;", checkbox);

Uncheck the Checkbox

📄
filename.js
js.executeScript("arguments[0].checked=false;", checkbox);

Or Click (simulates user click via JS)

📄
filename.js
js.executeScript("arguments[0].click();", checkbox);

3. Radio Button: Select

📄
filename.js
WebElement radioBtn = driver.findElement(By.id("genderMale"));

js.executeScript("arguments[0].checked=true;", radioBtn);

// Or to simulate a user click:

js.executeScript("arguments[0].click();", radioBtn);

4. Dropdown (Select): Set Value

For a simple <select> element:

📄
filename.js
WebElement dropdown = driver.findElement(By.id("country"));

js.executeScript("arguments[0].value='IN';", dropdown); // Set value attribute

If you want to trigger events (like change), do:

📄
filename.js
js.executeScript("arguments[0].value='IN'; arguments[0].dispatchEvent(new Event('change'));", dropdown);

For custom dropdowns:
Click to open and select an option using JS:

📄
filename.js
// Example: click the dropdown

js.executeScript("arguments[0].click();", dropdown);

// Then click the desired option (locate it first)

WebElement option = driver.findElement(By.xpath("//li[text()='India']"));

js.executeScript("arguments[0].click();", option);

5. Button: Click

📄
filename.js
WebElement button = driver.findElement(By.id("submitBtn"));

js.executeScript("arguments[0].click();", button);

Summary Table

ElementJavaScriptExecutor Example
Text boxarguments[0].value=’text’;
Checkboxarguments[0].checked=true; or .click();
Radioarguments[0].checked=true; or .click();
Dropdownarguments[0].value=’value’; + dispatchEvent(new Event(‘change’));
Buttonarguments[0].click();

Tips:

  • Always pass the element as an argument (see arguments[0]).
  • For dropdowns, ensure you match the correct value or text.

Use dispatchEvent(new Event(‘change’)) to trigger change handlers after setting values programmatically.

Selenium Automation Testing
What are your Feelings

Share This Article :

  • Facebook
  • X
  • LinkedIn
© 2018 – 2025 V-Tech Solutions Ltd (UK), Reg. No: 16489105