Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IF Then else statement
#1
Solved: 10 Years, 9 Months, 2 Weeks ago
Hi ALL,

I am novice in QTP. So could anybody explain me this small statemnt.

I am testing a .Net application where a scenario falls like this :
If 'Preferred comm' = Email. Enter email in the 'Email' field else if 'preferred comm' = fax. Enter fax in the 'Fax' field.

So, how do I write these statements in expert view? as I cannot select a object from object repository in expert view likewise in Keyword View. ???
Reply
#2
Solved: 10 Years, 9 Months, 2 Weeks ago
HI ,
You can use the If...Then...ElseIf statement if you want to select one of many blocks of code to execute.Then the statement as follows,
If 'Preferred comm' = Email.Enter email in the 'Email' field Then
Code:
document.write("..")
elseif 'preferred comm' = fax. Enter fax in the 'Fax' field Then
else
document.write("unknown")
End If

The above If...Then...ElseIf statement , you can write after 'Preferred comm' in expert view.
Reply
#3
Solved: 10 Years, 9 Months, 2 Weeks ago
Hey thanks jyo Smile
One more doubt to go Smile

In contest to above post. While running a test how do I select(Manually) preferred communication as Email/Phone/Fax so that respective field is filled with the value I specified in the script? Do I have to use a checkpoint before preferred comm statement?
Reply
#4
Solved: 10 Years, 9 Months, 2 Weeks ago
Hey can anybody help me urgent !!!!

Here are my if and else statements listed:

Code:
If Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").Select ("Email") = True Then
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtE").Set "swetha.b@osmosys.asia"
Elseif Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").Select ("Phone") = True Then
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtM").Set "(987)789-4563"
Else Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtF").Set "(876)567-3456"
End if

Logic is this: If preferred coom is Email : Fill Email field else if preferred comm is Phone : Fill Phone Filed else fill fax field.

My problem: Weblist - Preferred comm is always defaulted to "Email". So first time when I run the script First If statment should be true and execute immediate next statement. But inreturn execution goes to the Elseif statement and since elseif is also false last statmemt is excecuted. Implies Fax field is filled. Also noticed that after the elseif statement execution Preferred comm was set to Phone????
Reply
#5
Solved: 10 Years, 9 Months, 2 Weeks ago
Can anybody please provide me some help on this regard???
Reply
#6
Solved: 10 Years, 9 Months, 2 Weeks ago
Hi Swethaaaaaaa,

Code:
If Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").Select ("Email") = True Then

Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtE").Set "swetha.b@osmosys.asia"

Elseif Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").Select ("Phone") = True Then
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtM").Set "(987)789-4563"
End if

This will work
selected item should be verified as below

Code:
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").GetROProperty("Selection")="Email"[hr]
Here is the code

If Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").GetROProperty("Selection")="Email"Then

Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtE").Set "swetha.b@osmosys.asia"

Elseif Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").GetROProperty("Selection")="Phone" Then

Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtM").Set "(987)789-4563"

End if
Reply
#7
Solved: 10 Years, 9 Months, 2 Weeks ago
Hi Swetha, You can go this script , It may work .Here I used Exist Instead of (=True)
Code:
If Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").Select ("Email").Exist Then
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtE").Set "swetha.b@osmosys.asia"
Elseif Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").Select ("Phone").Exist Then
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtM").Set "(987)789-4563"
Else Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtF").Set "(876)567-3456"
End if
Reply
#8
Solved: 10 Years, 9 Months, 2 Weeks ago
Hi Jyo

statement

Code:
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").Select ("Email").Exist

will not work

Exist is used to check object and not value in weblist

~Nilesh
:-)
Reply
#9
Solved: 10 Years, 9 Months, 2 Weeks ago
Code:
var= Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").GetROProoerty("Selection")
Select Case "var"
Case ""
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtE").Set "swetha.b@osmosys.asia"
else if (var=Phone)
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtM").Set Set "(987)789-4563"
else if (var=FAX)
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtF").Set Set "(987)789-4563"[hr]
Please ignore y previous mail .. by mistake i clicked on the post repy...
u can also switch statement tocover the above scenario :
Code:
var= Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").GetROProoerty("Selection")
Select Case var
Case "Email"
    Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtE").Set "swetha.b@osmosys.asia"
  case "Phone"
        Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtM").Set  Set "(987)789-4563"
  case "FAX"
            Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebEdit("ctl00$ContentPlaceHolder1$txtF").Set " Set "(987)789-4563"
End Select
Reply
#10
Solved: 10 Years, 9 Months, 2 Weeks ago
hi

through this statement

Code:
Browser("TalonPro Solutions").Page("TalonPro Solutions_4").WebList("ctl00$ContentPlaceHolder1$ddlP").GetROProperty("Selection")

you can get the selected Item.
further you can implement it through any logic

Thanks
~Nilesh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)