Enabling/Disabling Text Box In Selenium IDE Using Javascript

Before discussing on enabling/disabling any element in selenium IDE, Let me tell you one thing - Selenium IDE is less powerful compared to Selenium RC and WebDriver, we can not perform all the tasks in selenium IDE. But still we can automate simple flows very easily in selenium IDE compared to webdriver because
selenium IDE is simple record and play tool and editing its script is also very easy. If you have not used selenium IDE any time then you can look at these SELENIUM IDE COMMANDS WITH EXAMPLES. Let me concentrate on current discussion point.

We have seen how to enable or disable text box in webdriver using javascript executor in THIS POST. Now if you wants to do same thing in selenium IDE then how can you do it? Yes selenium IDE is also supports javascript and we can do it very easily by using javascript with runScript command. You can view more examples of use of javascripts in selenium IDE on THIS LINK.

In bellow given example, 1st "runScript" command will disable First Name text box and 2nd "runScript" command will enable Last Name text box. Run it in your selenium IDE window and observe result in page. This way javascript makes strong to selenium IDE.


New Test
CommandTargetValue
setSpeed2000
openhttp://only-testing-blog.blogspot.com/2013/11/new-test.html
runScriptdocument.getElementsByName('fname')[0].setAttribute('disabled', '')
runScriptdocument.getElementsByName('lname')[0].removeAttribute('disabled');


1 comment:

  1. Thanks for the tutorial, gonna try it. However, textboxes can be not that annoying so you want to disable it. I like to test new features in textboxes with http://charts.poweredtemplate.com/powerpoint-diagrams-charts/ppt-text-boxes/0/index.html, and I must say that I've done a lot of useful stuff.

    ReplyDelete