Friday, June 14, 2013

Working with WebRadioGroup

QTP WebRadioGroup means a radio button on the web page. Identifying and working with them can be easy or difficult. Sometimes they works out fine and at times executing the same code gives you error. 

If you have two radio buttons on the screen for example Gender selection options the code below might give problem.

Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "Male"
Where "Male" can be the id or the value of the radio button (Spy the object). So what is the problem in the code above? As there are two radio buttons QTP identifies them as same, so we need to differentiate between them. Index is a property by which you can differentiate, it tells the position of the object. So if we write the same code below with an additional index property it will work fine.
Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender", "index:= 1").Select "Female"
This code is intended to select a radio button among two, what if you have a list of radio buttons let’s say 5-6 or more, than the above code won’t help. For that you need to create description of a radiogroup i.e. we will instruct everything to QTP.

''''''=====Initialize variables
Dim oWebRadio
Dim oWebRadioCount
Dim RadioToSelect_Val 

''''''Create description using Description.Create build-in method
Set oWebRadio = Description.Create
oWebRadio ("micclass").value = "WebRadioGroup"
oWebRadio ("type").value = "radio"
oWebRadio ("name").value="Gender"

''''''Pass the description in another variable using ChildObjects method
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").ChildObjects(oWebRadio)
''''''Loop to select desired value
For i = 0 to oWebRadioCount
RadioToSelect = oWebRadioCount (i).GetROProperty("value")
oWebRadioCount (i).Select RadioToSelect
Next

''''''Pass Child count in a variable
allItems = oChild.Count

''''''Loop & Use items count property to get Total items
For j = 0 to allItems-1
   itemsCount =oChild.Item(j).GetRoProperty("items count")

      If (itemsCount = 5) Then
          Print "Found 5 radio " 
      else
          Print "More than 5 radio listed"
      End If

Next

So there are two ways to deal with descriptive programming, either pass the properties directly or create your descriptions and pass or select your values.


'============= Ways to select value from WebList =======================

Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr").Select "#3"
Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr").Select "2218866589&15-5-2013"


Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "#0"
Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").WebRadioGroup("name:=Gender").Select "Female"


'========== To Count Number and Name of WebRadioGrouppresent on a Page Using MicClass ======

'Example: 1  This page has One Radio Group

SystemUtil.Run "iexplore", "http://youngistaancafe.blogspot.com/2013/07/qtp-web-table_5925.html"
Set oWebRadio = Description.Create
oWebRadio("micclass").value="WebRadioGroup"
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").ChildObjects(oWebRadio)
vrCount = oWebRadioCount.Count
msgbox vrCount

For i=0 to vrCount-1
msgbox oWebRadioCount(i).GetROProperty("name")
Next

'Example: 2 This page has Two Radio Groups

SystemUtil.Run "iexplore", "http://youngistaancafe.blogspot.com/2013/07/student-registration-formhtml.html"

Set oWebRadio = Description.Create
oWebRadio("micclass").value="WebRadioGroup"
Set oWebRadioCount = Browser("name:=Youngistaan Cafe: Student Registration Form.html").Page("title:=Youngistaan Cafe: Student Registration Form.html").ChildObjects(oWebRadio)
vrCount = oWebRadioCount.Count
msgbox vrCount

For i=0 to vrCount-1
msgbox oWebRadioCount(i).GetROProperty("name")
Next


'To find Number of Radio Buttons present in particular Group along with its value

With Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr")

vrAllItem = .GetROProperty("all items")
msgbox vrAllItem

vrArr = Split(vrAllItem, ";", -1, 1)

For i=0 to UBound(vrArr)
          msgbox vrArr(i)
          vrLeftPNR = Left(vrArr(i),10)
          msgbox vrLeftPNR
          If vrPNR = vrLeftPNR Then
                   vrIndex = i
        .Select "#"&vrIndex
                   Exit For
          End If
Next
End With


'=========Select  WebRadio button where PNR# is 5018866589================

vrPNR = "5018866589"
With Browser("name:=Youngistaan Cafe: QTP Web Table").Page("title:=Youngistaan Cafe: QTP Web Table").WebTable("name:=Passenger 1").WebRadioGroup("name:=rnd_pnr")

vrAllItem = .GetROProperty("all items")
msgbox vrAllItem

vrArr = Split(vrAllItem, ";", -1, 1)

For i=0 to UBound(vrArr)
          msgbox vrArr(i)
          vrLeftPNR = Left(vrArr(i),10)
          msgbox vrLeftPNR
          If vrPNR = vrLeftPNR Then
                   vrIndex = i
        .Select "#"&vrIndex
                   Exit For
          End If
Next
End With


30 comments:

  1. hi how to select radio buttons alternatively .......Tech mahendra question

    ReplyDelete
  2. U can use Index value ... and wid the help of loop... counter+2... u can select alternate radio buttons...

    ReplyDelete
  3. Hi Hardeep,
    This one is using descriptive programming,i need some hints how to work with datatable. Here i am having flightbooking as reusable action with 2 rows of testdata in datatable.
    now i have 2 Testcases like TC1 will apply call to existing and fetches 1st row data from datatable, but in TC5 i use copy to action and set to nextrow and works fine it till reaches the radio button option where i need to select different service class , it says object cannot be identified so how to work with radio buttons using datatable.

    ReplyDelete
  4. Ciitnoida provides Core and java training institute in noida. We have a team of experienced Java professionals who help our students learn Java with the help of Live Base Projects. The object-oriented, java training in noida , class-based build of Java has made it one of most popular programming languages and the demand of professionals with certification in Advance Java training is at an all-time high not just in India but foreign countries too.

    By helping our students understand the fundamentals and Advance concepts of Java, we prepare them for a successful programming career. With over 13 years of sound experience, we have successfully trained hundreds of students in Noida and have been able to turn ourselves into an institute for best Java training in Noida.

    java training institute in noida
    java training in noida
    best java training institute in noida
    java coaching in noida
    java institute in noida

    ReplyDelete
  5. Sap Training Institute in Noida

    CIIT Noida provides Best SAP Training in Noida based on current industry standards that helps attendees to secure placements in their dream jobs at MNCs. CIIT Provides Best ERP SAP Training in Noida. CIIT is one of the most credible ERP SAP training institutes in Noida offering hands on practical knowledge and full job assistance with basic as well as advanced level ERP SAP training courses. At CIIT ERP SAP training in noida is conducted by subject specialist corporate professionals with 7+ years of experience in managing real-time ERP SAP projects. CIIT implements a blend of aERPemic learning and practical sessions to give the student optimum exposure that aids in the transformation of naïve students into thorough professionals that are easily recruited within the industry.

    At CIIT’s well-equipped ERP SAP training center in Noida aspirants learn the skills for ERP SAP Basis, ERP SAP ABAP, ERP SAP APO, ERP SAP Business Intelligence (BI), ERP SAP FICO, ERP SAP HANA, ERP SAP Production Planning, ERP SAP Supply Chain Management, ERP SAP Supplier Relationship Management, ERP SAP Training on real time projects along with ERP SAP placement training. ERP SAP Training in Noida has been designed as per latest industry trends and keeping in mind the advanced ERP SAP course content and syllabus based on the professional requirement of the student; helping them to get placement in Multinational companies and achieve their career goals.

    ERP SAP training course involves "Learning by Doing" using state-of-the-art infrastructure for performing hands-on exercises and real-world simulations. This extensive hands-on experience in ERP SAP training ensures that you absorb the knowledge and skills that you will need to apply at work after your placement in an MNC.

    ReplyDelete
  6. You truly did more than visitors’ expectations. Thank you for rendering these helpful, trusted, edifying and also cool thoughts on the topic to Kate.

    Hadoop Training in Chennai

    ReplyDelete
  7. From your discussion I have understood that which will be better for me and which is easy to use. Really, I have liked your brilliant discussion. I will comThis is great helping material for every one visitor. You have done a great responsible person. i want to say thanks owner of this blog.

    python training in chennai | python training in bangalore

    python online training | python training in pune

    python training in chennai

    ReplyDelete
  8. Thank you so much for a well written, easy to understand article on this. It can get really confusing when trying to explain it – but you did a great job. Thank you!
    python training in tambaram
    python training in annanagar
    python training in Bangalore

    ReplyDelete
  9. Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way. T hank you so much.
    Web Designing Course in chennai
    web design training chennai
    web design training in chennai
    website designing training
    web designing training
    web designing in chennai

    ReplyDelete
  10. I think you have a long story to share and i am glad after long time finally you cam and shared your experience.
    online Python training | python training in chennai

    ReplyDelete
  11. I am really very happy to find this particular site. I just wanted to say thank you for this huge read!! I absolutely enjoying every petite bit of it and I have you bookmarked to test out new substance you post.
    Microsoft Azure online training
    Selenium online training
    Java online training
    uipath online training
    Python online training

    ReplyDelete
  12. this blog is very useful for who wants to learn DevOps course if you want to take DevOps training once go through thid blog.

    ReplyDelete
  13. Learn Amazon Web Services for excellent job opportunities from Infycle Technologies, the best AWS training institute in Chennai. Infycle Technologies gives the most trustworthy AWS course in Chennai, with full hands-on practical training from professional trainers in the field. Along with that, the placement interviews will be arranged for the candidates, so that, they can meet the job interviews without missing them. To transform your career to the next level, call 7502633633 to Infycle Technologies and grab a free demo to know more.Big Data Training in Chennai

    ReplyDelete
  14. Infycle Technologies, the No.1 software training institute in Chennai offers the No.1 Data Science course in Chennai for tech professionals and students at the best offers. In addition to the Data Science course, other in-demand courses such as Python, Selenium, Oracle, Java, Python, Power BI, Digital Marketing also will be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.

    ReplyDelete
  15. Infycle Technologies, the top software training institute and placement center in Chennai offers the Digital Marketing course in Chennai for freshers, students, and tech professionals at the best offers. In addition to the Oracle training, other in-demand courses such as DevOps, Data Science, Python, Selenium, Big Data, Java, Power BI, Oracle will also be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.

    ReplyDelete
  16. This post is so interactive and informative.keep update more information...
    Java Training in Tambaram
    java course in tambaram

    ReplyDelete
  17. Option catch tough begin perform. Effect military serious but management development.top 10 news today

    ReplyDelete