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.
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.
DescObject("micclass").value = "webcheckbox"
set col = Browser("myb").page("myp").childobjects(DescObject)
col(2).click
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.
We can solve this problem by 3 ways as mentioned below in QTP.
- Using index property
- Using Description object
- 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.
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs