I have been working on Ruby and Watir technologies for a while now. While enjoying the versatility of Watir (as evident from Željko Filipin’s Watir solution for playing pacman, http://zeljkofilipin.com/2010/05/29/play-google-pacman-with-watir/) – I realized that there are certain scenarios in which we do not have direct method for accomplishing a task. For example, when we have to deal with the dynamic content generated by ajax, there is no out-of-box method provided by Watir to enter the data. While working for different clients at 3Qi Labs, I have faced the problem of dynamic content manipulation over and over. Let us see what can be done in such situations.

drop down

So, here we go with a typical problem of entering data into an ajax table using Watir script. The Ajax controls can be tricky to handle. With one of our Ajax controls, once you click on the text field a drop down list appears, however this is not a list. To select a value from this list, you need to open it. You might be thinking, why not type the option text directly in the text field, but unfortunately the text field is not available until you click on the drop down. So, how to handle it?

Here is what I did:

If you are wondering what me set_table_cell_textfield_by_class method is doing, here is what I have in there:

In non-technical terms, I click on the table cell where the ajax drop down exists. I capture the text field using its class property and enter the required value in there. After that, to ensure that the value is saved, I click into the text field again which closes the drop down and saves the value into the text field.

Just make sure you capture the right text field…else it might not retain the value entered…

Happy Scripting…Happy Testing!!!

Enhanced by Zemanta