Make Selenium Easy

How to validate paste disabled input box using Selenium WebDriver

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

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.

How to validate copy-paste disabled input box using Selenium?

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.

Selenium – WebDriver – Java Code:-

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

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

How to validate paste disabled input box using Selenium WebDriver

by Amod Mahajan time to read: 2 min
0
%d bloggers like this: