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
    • E-Commerce Demo Application
    • 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
    • E-Commerce Demo Application
    • 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 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

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

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

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

Uncheck the Checkbox

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

Or Click (simulates user click via JS)

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

3. Radio Button: Select

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:

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:

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:

// 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

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
How to handle scroll function using JavaScriptExecutor?How to handle advanced functionality using JavaScriptExecutor?
© 2018 – 2025 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105