Try Catch
- This topic has 3 replies, 2 voices, and was last updated 6 years, 5 months ago by Sasha ZAP.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
Home › Forums › Ask Expert › Try Catch
Hi there,
I’m trying to select a date from a Calendar using your example (with a table). However if I what to select a pre-selected date I can’t because on my app it will be displayed like [8] instead of 8 and ZapTest can’t find it. I tried to use a Try Catch to select another date case mine was pre-selected (not found) but no success because the catch never run.
Any idea how to solve that?
try{
Application("Myapp").View("SelDate").Object("Calendar").Table("Date").ClickCell(Datatable.Value("Date"));}
catch(e){
Application("Myapp").View("SelDate").Object("Calendar").Table("Date").ClickCell(Datatable.Value("Date"));}
Hello nuno.seixas,
There are 3 options you can try in order the Table object will recognize its specific cell:
1. Add the Boolean statement “True” at the end of the code line, this will ensure the Table object will be set to handle a Web Calendar object type:
Application(“Myapp”).View(“SelDate”).Object(“Calendar”).Table(“Date”).ClickCell Datatable.Value(“Date”), True
2. Use the same “Clickcell” method’s attributes but this time instead of using the cell number use string such as:
Application(“Myapp”).View(“SelDate”).Object(“Calendar”).Table(“Date”).ClickCell “[8]”, True
3. Basically there are another “Clickcell” method’s attributes, which help locate the specific cell by its row and column, you can set them instead of the specific column’s cell text – For example today’s date (The 10th of July) in the Windows’ OS based calendar it will be the row 3 and the column 3, so if you’d like to click on it your code will be:
Application(“Myapp”).View(“SelDate”).Object(“Calendar”).Table(“Date”).ClickCell 3, 3
Hope this helps.
Thanks,
ZAPTEST Team
Hello SashaY,
Thanks for your answer.
Problem is, I never know if the date what I want to pick from the calendar has the [] or not.
For example, if I want 4, I don’t know if in the calendar I have 4 or [4].
I want something like if(4 exist) {sel 4} else { sel [4] }
Thanks.
Hello nuno.seixas,
Basically you can add a similar condition as the following one:
bFound = False
intNumofRows = Application(“Myapp”).View(“SelDate”).Object(“Calendar”).Table(“Date”).GetRows
inNumoftColumns = Application(“Myapp”).View(“SelDate”).Object(“Calendar”).Table(“Date”).GetColumns
For i = 1 To intNumofRows
For j = 1 to inNumoftColumns
strCellText = Application(“Myapp”).View(“SelDate”).Object(“Calendar”).Table(“Date”).GetCellText(i, j)
If InStr(strCellText, “8”) Then
bFound = True
Application(“Myapp”).View(“SelDate”).Object(“Calendar”).Table(“Date”).ClickCell i, j
Exit For
ElseIf InStr(strCellText, “[8]”) Then
bFound = True
Application(“Myapp”).View(“SelDate”).Object(“Calendar”).Table(“Date”).ClickCell i, j
Exit For
End If
Next
If bFound = True Then
Exit For
End If
Next
If bFound = False Then
Application(“Myapp”).View(“SelDate”).Object(“Calendar”).Table(“Date”).Report False, “Cell Error”, “The cell ‘8’ or ‘[8]’ was not found.”, True
End If
Thanks,
ZAPTEST Team
Already have an account? Login
Check you SPAM folder if you do not see the email.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |