Qtp Tip To Deselect All Radio Buttons

2
Yesterday I got an email from one of my esteemed readers who asked "Is there any way to deselect all radio buttons using HP QTP?" I thought why one would do that but since it has been asked, it has to be answered. Before answering the above question let me explain that, radio buttons work in groups unlike checkboxes. It means, in a group only a single radio button can be selected. Afterwards, its not possible to deselect all radio buttons in that group. Even manually it can not be done. Inititally the task seems impossible but its not :) It is definitely possible to deselect all radio buttons using QTP but it can only be achieved with the help of Document Object Model or DOM. The QTP Script for the same goes here: Set Obj =Browser("Google").Page("Google").object.getElementsByT agName("INPUT") For each RadioBtn in Obj If lcase(RadioBtn.type) = "radio" Then RadioBtn.checked = False Next To know more about the Document Object Model in QTP, see here :http://msdn.microsoft.com/en-us/library/ms533043(VS.85 ).aspx

Transcript of Qtp Tip To Deselect All Radio Buttons

Page 1: Qtp Tip To Deselect All Radio Buttons

Yesterday I got an email from one of my esteemed readers who asked "Is there any way to deselect all radio buttons using HP QTP?" I thought why one would do that but since it has been asked, it has to be answered.

Before answering the above question let me explain that, radio buttons work in groups unlike checkboxes. It means, in a group only a single radio button can be selected. Afterwards, its not possible to deselect all radio buttons in that group. Even manually it can not be done.

Inititally the task seems impossible but its not :)

It is definitely possible to deselect all radio buttons using QTP but it can only be achieved with the help of Document Object Model or DOM.

The QTP Script for the same goes here:

Set Obj =Browser("Google").Page("Google").object.getElementsByTagName("INPUT")

For each RadioBtn in ObjIf lcase(RadioBtn.type) = "radio" Then RadioBtn.checked = FalseNext

To know more about the Document Object Model in QTP, see here :http://msdn.microsoft.com/en-us/library/ms533043(VS.85).aspx

Also read about the Object property in WebRadioGroup Object in QTP help for more information.

Note:

Document Object model is supported by Internet Explorer browser only & not for Firefox as the underlying COM technology is not supported by Firefox. Hence, for Firefox browser, QTP will not be able to access the radio buttons using Document Object Model.

Also working with Document Object Model inside HP Quicktest Professional is faster in terms of performance as no object identification is involved.

You can read more QTP article here: HP QTP Blog