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

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

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.