Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

How to validate paste disabled input box using Selenium WebDriver

Posted on 02/19/2025 By admin

You must have seen some input text boxes where you can not copy-paste a value. For example:- In a banking application, account number field may not allow you to copy paste a value. If you try pasting a value in that input text box, it will not show any entered value.

A copy paste disabled web element can be created in multiple ways. An example is as below:-

 Enter Account Number : 

Save above html code in a .html file and open in a browser. Try to copy paste a value in to it. You will not be able to do so. Now enter some values in text box manually and try to copy it. You will not able to do so as well.

This may sound complex but it is not at all. Just you need to observe the html code of web element carefully and find out the attributes which make it copy – paste disabled.

Let’s start to find those attributes.

If see html code of above web element , you will see four attributes:-

oncopy , ondrag, ondrop and onpaste

In fact above four are event attributes and it is fired when specific action i.e. copy, paste, drag and drop are performed. If you see value of these attributes it is returning false which triggers no event and restrict copy, paste, drag and drop.

You just need to assert values of these attributes in Selenium WebDriver. Again I am repeating that developers may develop the same feature in different ways as well. You just need to find correct attributes.

package ScenarioBased;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

import io.github.bonigarcia.wdm.WebDriverManager;

public class VerifyCopyPasteDisabledTextBox {

        @Test
        public void verifyCopyPasteDisabledTextBox() {
                
                // Browser initialization
                WebDriverManager.chromedriver().setup();
                WebDriver driver = new ChromeDriver();
                String fileURL = System.getProperty("user.dir");
                driver.get(fileURL + "/src/test/resources/htmlFiles/PasteDisabled.html");
                
                // Verify input box is copy disabled
                WebElement txtBoxAccountNumber = driver.findElement(By.name("ReceiveNo"));
                String onCopyVal = txtBoxAccountNumber.getAttribute("oncopy");
                System.out.println("On copy value = "+onCopyVal);
                Assert.assertTrue(onCopyVal.contains("false"));
                // Verify input box is paste disabled
                String onPasteVal = txtBoxAccountNumber.getAttribute("onpaste");
                System.out.println("On paste value = "+onPasteVal);
                Assert.assertTrue(onPasteVal.contains("false"));
                driver.quit();
        }

}

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: API Testing Tutorial Part 13 – What is a Payload in an API?
Next Post: Understand Defect Life Cycle In Testing

Related Posts

java interview question Uncategorized
TestNG Tutorials 42: Parameters In TestNG or Parameterization of Methods in a TestNG Class | Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
Object Repository in Selenium Using Page Factory With Inner Class – Handling a Page Which Has Many Webelements | Make Selenium Easy Uncategorized
July 1, 2018 – Make Selenium Easy Uncategorized
Skipped1 – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark