Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repeating If loop
#1
Solved: 11 Years, 4 Months ago
The loop below checks a date range, if no data is returned, a new date is used. If the 1st date fails, I check another date.

How can I better check if no data is found without using an If statement within an If statement?

Do loop?

My code:

Code:
If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").Exist(5) Then
        'No data found for ACCT1 in ENV
        Reporter.ReportEvent micFail,"No Data found for Row:  " & DataTable.GlobalSheet.GetCurrentRow, " The Account Number: " & Datatable("ACCT1", dtGlobalSheet) & " in the ENV: " & Datatable("ENV", dtGlobalSheet) & " - has no Data."
        'Try secondary End Date (eDate2)
        Browser("Wisdom").Page("Wisdom IA").Frame("parent").Image("button_newsearch").Click
        Browser("Fax Request").Page("Preferences").WebEdit("EndDate").Set eDate2 '=  "03/25/2011"
        Browser("Fax Request").Page("Preferences").WebElement("SearchPrefPage").Click
        If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").Exist(5) Then
            Reporter.ReportEvent micFail,"No Data found for Row:  " & DataTable.GlobalSheet.GetCurrentRow, " The Account Number: " & Datatable("ACCT1", dtGlobalSheet) & " in the ENV: " & Datatable("ENV", dtGlobalSheet) & " - has no Data."
            ExitTest
        Else
        'data found for ACCT1 in ENV
        Reporter.ReportEvent micPass, "Data found for Row:  " & DataTable.GlobalSheet.GetCurrentRow, " The Account Number: " & Datatable("ACCT1", dtGlobalSheet) & " in the ENV: " & Datatable("ENV", dtGlobalSheet) & " - has Data."
        End If
Else
        'data found for ACCT1 in ENV
        Reporter.ReportEvent micPass, "Data found for Row:  " & DataTable.GlobalSheet.GetCurrentRow, " The Account Number: " & Datatable("ACCT1", dtGlobalSheet) & " in the ENV: " & Datatable("ENV", dtGlobalSheet) & " - has Data."
End If
Reply
#2
Solved: 11 Years, 4 Months ago
Lorena,

Its not clear what you want to achieve. Just add some screenshots and details.

Regards,
Parminder
Reply
#3
Solved: 11 Years, 4 Months ago
Screenshots wont help, this is more of a coding issue.

Let me try and better explain.

I search on a StartDate to an EndDate. If I get no data returned to my screen, an error message indicates "No Results Found".

If no results are found, I want to notify that the first date failed and thus try a second date (by taking today's date minus 1 day). If the second try fails, I know to exit from this test only.

Beter?

;-)?
Reply
#4
Solved: 11 Years, 4 Months ago
Lorena,

Your code seems right. Does that return any error? If not then OK to use that code. Maybe somebody else make it perform better Smile ?

Regards,
Parminder
Reply
#5
Solved: 11 Years, 4 Months ago
Thx Parminder,

I do not get an error, but ...

First,
I changed my code. The first If stement (when no data is retevied) works fine. But the second If statement Still goes to fail even though data is present on the page. I get a warning stating that

Warning or Fail
"If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").GetROProperty("visible") = True Then" is not found.

My code gives me a warning or fails when WebElement("No Results Found") is not found. My goal is to check if the WebElement("No Results Found") is displayed, if it is then use today's date minus one day. Then check again if WebElement("No Results Found") is visible.

But if WebElement("No Results Found") is not visible (as data is present), my code still marks as Fail.

How can I better check for the message ("No Results Found")? and continue if not found.

Second,
My date code:
TodayDate = DateAdd("d",-1,Now())
eDate = FormatDateTime(TodayDate,2)

returns 7/1/2011, but this fails as the program only alows mm/dd/yyyy (so, Im need 07/01/2011) or I get an error message.

My code:

Code:
CurrentRow =  DataTable.GlobalSheet.GetCurrentRow
ACCT = Datatable("ACCT1", dtGlobalSheet)
ENV = Datatable("ENV", dtGlobalSheet)

If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").GetROProperty("visible") = True Then
      'No data found for EndDate in ENV
       eDate = DateAdd("d",-1,Now())
      eDate = FormatDateTime(eDate,2)
        'Try secondary End Date (Today minus 1 day)
      Browser("Wisdom").Page("Wisdom IA").Frame("parent").Image("button_newsearch").Click
      Browser("Fax Request").Page("Preferences").WebEdit("EndDate").Set eDate
      Browser("Fax Request").Page("Preferences").WebElement("SearchPrefPage").Click
      If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").GetROProperty("visible") = True Then
         Reporter.ReportEvent micFail,"No Data found for Row:  " & CurrentRow & " The Account Number: " & ACCT & " in the ENV: " & ENV & " - has no Data."
         ExitTest
      Else
      'data found for EndDate in ENV
      Reporter.ReportEvent micPass, "Data found for Row:  " & CurrentRow & " The Account Number: " & ACCT & " in the ENV: " & ENV & " - has Data."
      End If
Else
      'data found for EndDate in ENV
      Reporter.ReportEvent micPass, "Data found for Row:  " & CurrentRow & " The Account Number: " & ACCT & " in the ENV: " & ENV & " - has Data."
End If
Reply
#6
Solved: 11 Years, 4 Months ago
Quote: Warning or Fail
"If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").GetROProperty("visible") = True Then" is not found.

My code gives me a warning or fails when WebElement("No Results Found") is not found. My goal is to check if the WebElement("No Results Found") is displayed,
You can not use GetRoProperty for an object which doesn't exist(in your case it may/'nt exist)
so use .Exist method again as you used in first line


If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").Exist(5) Then

And to make your code look better, use a function to test data availability by just passing date parameter and get the returned value as boolean found or not found

By the way "If" is not a loop, it's a conditional statement!
Reply
#7
Solved: 11 Years, 4 Months ago
Thx, I did this last week. I just used todays date minus 1, then I checked with Exist but only one time. If no data exists then I fail and move on.

thx for the help ;-)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FOR LOOP shayk1985 1 5,309 12-13-2012, 11:35 AM
Last Post: sams001
  How to exit from a for loop silpavinod 2 9,889 10-17-2012, 12:55 AM
Last Post: agarwl.anurag
  for loop sia sharma 1 3,343 09-13-2012, 11:44 AM
Last Post: ksrikanth2k9
  Help with Loop LJENNE 1 3,193 08-10-2012, 12:32 PM
Last Post: Ankesh
  How to get out of infinite FOR loop... sssidana 3 4,567 07-20-2012, 01:04 AM
Last Post: sree.85

Forum Jump:


Users browsing this thread: 1 Guest(s)