Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to exit from a for loop
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
Code:
Browser("Link Express - Booking").Page("Link Express - Booking").Link("Booking").Click
Browser("Link Express - Booking").Page("Link Express - Booking").Link("Create").Click
Browser("Link Express - Booking").Page("Link Express - Booking").WebElement("FMCG Food and Drink Drink").Highlight

Set odesc=Description.Create
odesc("micclass").value="WebElement"
odesc("html tag").value="SPAN"
odesc("class").value="rtPlus"
Set val= Browser("Link Express - Booking").Page("Link Express - Booking").WebElement("FMCG Food and Drink Drink").ChildObjects(odesc)
Msgbox val.count
For i=0 to val.count-50
    val(i).highlight
    val(i).click
'a=val(i).GetROProperty("innertext")
'Msgbox a

Set odesc1=Description.Create
odesc1("micclass").value="WebElement"
odesc1("html tag").value="SPAN"
odesc1("class").value="rtIn"
Set val1= Browser("Link Express - Booking").Page("Link Express - Booking").WebElement("FMCG Food and Drink Drink").ChildObjects(odesc1)
Msgbox val1.count

For  j=0 to val1.count-270
a=val1( j ).GetROProperty("innertext")
Msgbox a
val1(j).Highlight
Ifa="Beer"Then
    Msgbox "Beer"
    Val1(j).click
    Exit For
    Exit For
    else
    Msgbox "Failed"
End If
Next
Next


This is my code .... here the prblm is if a= "beer" it should select and exit the loop

I am able to select but i am not able to exit frm loop

help me....
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
Put the second exit for after the first next statement

Code:
Browser("Link Express - Booking").Page("Link Express - Booking").Link("Booking").Click
Browser("Link Express - Booking").Page("Link Express - Booking").Link("Create").Click
Browser("Link Express - Booking").Page("Link Express - Booking").WebElement("FMCG Food and Drink Drink").Highlight

Set odesc=Description.Create
odesc("micclass").value="WebElement"
odesc("html tag").value="SPAN"
odesc("class").value="rtPlus"
Set val= Browser("Link Express - Booking").Page("Link Express - Booking").WebElement("FMCG Food and Drink Drink").ChildObjects(odesc)
Msgbox val.count
For i=0 to val.count-50
    val(i).highlight
    val(i).click
'a=val(i).GetROProperty("innertext")
'Msgbox a

Set odesc1=Description.Create
odesc1("micclass").value="WebElement"
odesc1("html tag").value="SPAN"
odesc1("class").value="rtIn"
Set val1= Browser("Link Express - Booking").Page("Link Express - Booking").WebElement("FMCG Food and Drink Drink").ChildObjects(odesc1)
Msgbox val1.count

For  j=0 to val1.count-270
a=val1( j ).GetROProperty("innertext")
Msgbox a
val1(j).Highlight
Ifa="Beer"Then
    Msgbox "Beer"
    Val1(j).click
    Exit For
    
    else
    Msgbox "Failed"
End If
Next
Exit For
Next
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi,

You can modify the code like this:
Code:
Browser("Link Express - Booking").Page("Link Express - Booking").Link("Booking").Click
Browser("Link Express - Booking").Page("Link Express - Booking").Link("Create").Click
Browser("Link Express - Booking").Page("Link Express - Booking").WebElement("FMCG Food and Drink Drink").Highlight

Set odesc=Description.Create
odesc("micclass").value="WebElement"
odesc("html tag").value="SPAN"
odesc("class").value="rtPlus"
Set val= Browser("Link Express - Booking").Page("Link Express - Booking").WebElement("FMCG Food and Drink Drink").ChildObjects(odesc)
Msgbox val.count
For i=0 to val.count-50
    val(i).highlight
    val(i).click
'a=val(i).GetROProperty("innertext")
'Msgbox a

Set odesc1=Description.Create
odesc1("micclass").value="WebElement"
odesc1("html tag").value="SPAN"
odesc1("class").value="rtIn"
Set val1= Browser("Link Express - Booking").Page("Link Express - Booking").WebElement("FMCG Food and Drink Drink").ChildObjects(odesc1)
Msgbox val1.count

For  j=0 to val1.count-270
a=val1( j ).GetROProperty("innertext")
Msgbox a
val1(j).Highlight
Ifa="Beer"Then
    Msgbox "Beer"
    Val1(j).click

       [undefined=undefined] var=1[/undefined]
    Exit For

    else
    Msgbox "Failed"
End If
Next
[undefined=undefined]If var=1 then
    Exit For
End if[/undefined]
Next

Thanks
Anurag
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Close on Exit Issue in QTP 11.0 EGBELL 1 3,232 02-02-2014, 03:39 PM
Last Post: EGBELL
  exit parent functions as well Shridevi.Salagare 3 3,917 07-31-2013, 12:15 AM
Last Post: Ankur
  FOR LOOP shayk1985 1 5,353 12-13-2012, 11:35 AM
Last Post: sams001
  for loop sia sharma 1 3,358 09-13-2012, 11:44 AM
Last Post: ksrikanth2k9
  Help with Loop LJENNE 1 3,206 08-10-2012, 12:32 PM
Last Post: Ankesh

Forum Jump:


Users browsing this thread: 1 Guest(s)