Selenium: How do I use javascript to clear a value from a form field? Selenium: How do I use javascript to clear a value from a form field? selenium selenium

Selenium: How do I use javascript to clear a value from a form field?


You can do it via javascript as such:

| verifyEval | javascript{this.browserbot.getCurrentWindow().document.getElementById('CONTROL_ID').value = ''} || 

Effectively the verifyEval statement allows you to execute any piece of javascript that you'd like. Makes some difficult problems to accomplish with Selenium much simpler.

I used this tutorial (today believe it or not) to figure things out.


I used this to get it to work. reg_start_date is the id of my input field.

| storeEval | window.document.getElementById('reg_start_date').value = '' |

From the selenium reference:

Note that, by default, the snippet will run in the context of the "selenium" object itself, so this will refer to the Selenium object. Use window to refer to the window of your application, e.g. window.document.getElementById('foo')

Also, avoid wrapping the javascript code with javascript{}, it will not work.


We had this issue at the beginning as well. Try: | type | text_field | blank |

Look for more info on the Fitnesse documentation for the use of blank and null.

:)