Micro Focus QTP (UFT) Forums
IF Then else statement - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: IF Then else statement (/Thread-IF-Then-else-statement--2787)

Pages: 1 2


IF Then else statement - swetha.b - 12-03-2009

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. ???


RE: IF Then else statement - Jyobtech - 12-03-2009

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.


RE: IF Then else statement - swetha.b - 12-03-2009

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?


RE: IF Then else statement - swetha.b - 12-04-2009

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????


RE: IF Then else statement - swetha.b - 12-04-2009

Can anybody please provide me some help on this regard???


RE: IF Then else statement - nil - 12-04-2009

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



RE: IF Then else statement - Jyobtech - 12-04-2009

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



RE: IF Then else statement - nil - 12-04-2009

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
:-)


RE: IF Then else statement - MahalakshmiDevi - 12-04-2009

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



RE: IF Then else statement - nil - 12-04-2009

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