Saturday 18 January 2014

How to select specific webcheckbox in QTP?

Sometimes there are webpages having multiple check boxes. You have to select specific check box.

We can solve this problem by 3 ways as mentioned below in QTP.

  1. Using index property
  2. Using Description object
  3. Using HTML DOM

Selecting the web check box using index -


if Browser("myb").page("myp").webcheckbox("index:=2").getROProperty("checked") = false then
     Browser("myb").page("myp").webcheckbox("index:=2").click
end if
'Above code will select the third checkbox on the webpage.

Selecting the web check box using Description Programming -

Set DescObject = Description.create()
DescObject("micclass").value = "webcheckbox"

set col = Browser("myb").page("myp").childobjects(DescObject)
col(2).click

Selecting the web check box using HTML DOM -

set col = Browser("myb").page("myp").object.getElementsByTagName("input")

'Please note that above statement will give you all the elements on the webpage having input tag.
You can check the innerhtml property of each element to see if the given input element's type is a checkbox or not.

for i=0 to i<col.count
x = col(i).getAttribute("type")
if lcase(trim(x)) = "checkbox" then
col(i).checked = true
end if
next

'Above code will select the first checkbox on the web page in QTP.

We can use same concept to select the specific check box in other environments like Java, .Net etc.


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.