How does navigate work?

110 views
Skip to first unread message

Sushma Jain

unread,
Dec 26, 2012, 5:36:38 PM12/26/12
to qtp-ele...@googlegroups.com
Hello Karthik,

I couldn't find solution to the following problem:

It is related to the QTP Day 3, Video 1. As working example of navigating from one website to another has not been explained before this video, I am facing a problem running the following code.

SystemUtil.Run "iexplore.exe","http://www.bankrate.com/calculators/mortgages/mortgage-calculator.aspx"
browser("Mortgage Calculator").Navigate ("http://www.mortgagecalculator.org")  

It opens the first website on bankrate.com but remains on the same website even after running the second line. The video is about creating two functions to calculate and compare the mortgage payments by two different sites but without successful navigation it doesn't seem to work out. I tried replacing the second address with different one also.

regards,

Sushma

Dineshkumar Rajendran

unread,
Dec 26, 2012, 5:59:33 PM12/26/12
to Sushma Jain, QTP eLearn Team
Hello Sushma,

Try using wait statement like below

wait 3
browser("Mortgage Calculator").Navigate ("http://www.mortgagecalculator.org") 
wait 3

Please let me know if this helps. If this does not work, please send me the code for debugging the issue.

Thanks,
Dinesh


--
You received this message because you are subscribed to the Google Groups "QTP eLearn Team" group.
To unsubscribe from this group, send email to qtp-elearn-te...@googlegroups.com.
Visit this group at http://groups.google.com/group/qtp-elearn-team?hl=en-US.
 
 

Sushma Jain

unread,
Dec 27, 2012, 1:18:57 PM12/27/12
to qtp-ele...@googlegroups.com, Sushma Jain
Hello Dinesh,

Thanks for the suggestion. Unfortunately, wait statement even for upto 30 sec does not work. My code is as follows(pl. refer video 1 Chapter 3). Would be grateful if you could help please.

Option explicit 'Forces the definition using Dim statement for all the variables
Dim vLoan, vTerm, vRate 'Not mandatory to define however agood practice
Dim br_op, mc_op
Dim vIter
Dim br_com, mc_org

'Open browser
'Repeat x number of times
'For vIter = 1 to 2
'Parameters can change values
vLoan = "350000"
vTerm = inputbox("Enter term of the loan")
vRate = "4"

'msgbox vLoan & vTerm & vRate
print vLoan & vTerm & vRate

'Application 1 : Bankrate.com

Set br_com = browser("Mortgage Calculator").Page("Bank Rate") 'Reference or shortcut of the page
br_com.WebEdit("LoanAmount").Set vLoan
br_com.WebEdit("Term").Set vTerm
br_com.WebEdit("Rate").Set vRate
br_com.WebList("Lmonth").Select "Jan"
br_com.WebList("Ldate").Select "12"
br_com.WebButton("Calculate").Click

wait 3
br_op = br_com.WebEdit("Payment").GetROProperty("value")
msgbox "monthly payment " & br_op

wait 3
'Application 2 : Mortgage Calculator.com
'Add objects to local then write the logic and navigate to different URL
browser("Mortgage Calculator").Navigate ("http://www.mortgagecalculator.org/")

'Create a bank object mc_org and put a pointer to that specific page
Set mc_org = browser("Mortgage Calculator").Page("MC Org")
mc_org.WebEdit("param[principal]").Set vLoan
mc_org.WebEdit("param[term]").Set vTerm
mc_org.WebEdit("param[interest_rate]").Set vRate
mc_org.WebEdit("param[property_tax]").Set "0"
mc_org.WebEdit("param[pmi]").Set "0"
mc_org.WebButton("Calculate").Click

'Synchronization points are aimed at synchronizing the object or app or bringing to a specific state before continuing
'mc_org.Sync   'Sync will instruct QTP to wait for  MC Org page to get loaded before proceeding to next step
wait 3  'Different from sync when you don't know how long to wait.

browser("Mortgage Calculator").Page("MC Org").Output CheckPoint("mcorg_op")
msgbox environment("mcorg_op") 'To get out of an environment variable

msgbox mc_org.WebElement("Payment").GetROProperty("innertext")


'next

Dineshkumar Rajendran

unread,
Dec 27, 2012, 1:57:10 PM12/27/12
to Sushma Jain, QTP eLearn Team
Hi

I tried your code on my local. I didn't get any problem. Try the below code and execute again. Please let me know if this works.


Option Explicit ' Forces the definition using the Dim statement for all variables
Dim vLoan, vTerm, vRate ' Not mandatory to define variables, however it is a good practice
Dim br_op, mc_op
Dim vIter
Dim br_com, mc_org

' open browser

' Repeat x number of times/ ITERATE X NUMBER TIMES
For vIter  = 1 to 2

' Parameters can change values
vLoan = "350000"
vTerm = inputbox("Enter Term of the Loan")
vRate = "4"
'msgbox vLoan & vTerm & vRate
print vLoan & vTerm & vRate

' Application 1 : Bankrate.com
Set br_com = browser("Mortgage Calculator").page("Bank Rate") ' Ref or shortcut to the page
br_com.WebEdit("LoanAmount").Set vLoan
br_com.WebEdit("Term").Set vTerm
    br_com.WebEdit("Rate").Set vRate
    br_com.WebList("Lmonth").Select "Jan"
br_com.WebList("Ldate").Select "12"
br_com.WebButton("Calculate").Click

br_op = br_com.WebEdit("Payment").GetROProperty("value")
    msgbox br_op

' Application 2: Mortgagecalculator.com
' Add objects to local, then write the logic
' Navigates to a different URL
browser("Mortgage Calculator").Navigate "http://www.mortgagecalculator.org"

' Creates a blank object mc_org and puts a pointer to that specific page
Set mc_org = browser("Mortgage Calculator").Page("MC Org") 

mc_org.WebEdit("param[principal]").Set vLoan
mc_org.WebEdit("param[term]").set vTerm
mc_org.WebEdit("param[interest_rate]").Set vRate
mc_org.WebEdit("param[property_tax]").Set "0"
mc_org.WebEdit("param[pmi]").Set "0"
mc_org.WebButton("Calculate").Click

' Synchronization points are aimed at synchronizing the object or app or bringing to a specific state before continuing
mc_org.Sync ' Sync will instruct QTP to wati for the mc_org page to get loaded before proceeding to next step
' wait 3 ' Diff with sync u dont know how long to wait. 

Browser("Mortgage Calculator").Page("MC Org").Output CheckPoint("mcorg_op")
msgbox environment("mcorg_op") ' To get value out of a environment variable
' msgbox mc_org.WebElement("payment").GetROProperty("outertext")

Next


Thanks,
Dinesh

Sushma Jain

unread,
Dec 27, 2012, 3:04:34 PM12/27/12
to qtp-ele...@googlegroups.com
Hello Dinesh,

many thanks for the prompt response. I am really surprised that the code works in your machine. Your code is not different except that you have enabled for loop. In my machine it opens "http://www.bankrate.com/calculators/mortgages/mortgage-calculator.aspx" successfully and shows the first message box with the value in br_op

After that it executes all the steps but doesn't open http://www.mortgagecalculator.org website. Again it runs the second set of code for setting up various values till the calculate button. It should capture the result of "Payment" webelement in mcorg_op environment variable and display in message box. But the message displayed is blank.

I feel it is happening because http://www.mortgagecalculator.org does not load after navigation from the previous one.

Is there any difference between your and mine object repository?

I have only one browser "Mortgage Calculator" which has two pages Bank Rate and MC Org with only one difference that "Payment" in Bank Rate page is WebElement and is a WebElement in other one.

Also I don't understand why I am getting blank message box for mcorg_op environment variable?

regards

Sushmaa

Dineshkumar Rajendran

unread,
Dec 27, 2012, 3:19:01 PM12/27/12
to Sushma Jain, QTP eLearn Team
OK, this might be issue with capturing Text Output value. Pleas check Output value summary in the OR check point, it should displays like "Output the text that is displayed between Repayment Summary and Monthly payment into <mcorp_op>. Refer the attached screenshot.


--
Output text.JPG

Sushma Jain

unread,
Dec 27, 2012, 4:53:46 PM12/27/12
to qtp-ele...@googlegroups.com, Sushma Jain
Hello Dinesh,

I just checked the OR and output value summary. It is exactly same as the screen shot sent by you. Please note that I am using QTP 11.00, IE 9 and Windows 7.

regards,

Sushma

Sushma Jain

unread,
Dec 27, 2012, 5:50:37 PM12/27/12
to qtp-ele...@googlegroups.com, Sushma Jain
Please also mention that while navigating you actually see the other application...Thanks

Dineshkumar Rajendran

unread,
Dec 27, 2012, 5:56:41 PM12/27/12
to Sushma Jain, QTP eLearn Team

Very Interesting.  I verified on both OS and different QTP versions, worked fine.

QTP 11.00, IE 9 and Windows 7
QTP 10.00. IE 8, XP

Navigation was done successfully. Can you zip your entire QTP test and send to me.

THanks,
Dinesh

Sushma Jain

unread,
Dec 27, 2012, 6:22:27 PM12/27/12
to qtp-ele...@googlegroups.com, Sushma Jain
Hello Dinesh,

Please find the attached zipped file.

regards
Mortgage_Calculator1_r.zip

Dineshkumar Rajendran

unread,
Dec 27, 2012, 6:47:21 PM12/27/12
to Sushma Jain, QTP eLearn Team
Hi,

Your script works absolutely fine at my end.

Thanks,
Dinesh

Sushma Jain

unread,
Dec 28, 2012, 7:50:36 AM12/28/12
to qtp-ele...@googlegroups.com, Sushma Jain
Hello Dinesh,

Sorry to bother you again. Probably, you may receive this message twice as first time it showed some error.

Its really surprising to know that the script I sent works fine with you. Actually, it executes without any error even in my machine but I see following problems:

1. After executing the "navigate" method the browser does not show up "www.mortgagecalculator.org" application.
2. The output captured in environment variable mcorg_op from the execution of second application show blank messagebox.

Any guesses why it is behaving so in my machine?

Can you please send screen shots of these steps?

regards,

Sushma

Dineshkumar Rajendran

unread,
Dec 28, 2012, 1:33:01 PM12/28/12
to Sushma Jain, QTP eLearn Team
Hello,

That's OK. Attached the screenshots in doc file.

It's weird behavior at your end, not 100% sure exactly why? So problem only with this script or for all scripts? Check all the default settings (IE, User control)?

Thanks,
Dinesh
Run_Screenshot.doc

aruna

unread,
Dec 28, 2012, 3:08:36 PM12/28/12
to qtp-ele...@googlegroups.com, Sushma Jain

Hi Sushma,

I am following ur conversation from y'day onwards, I tried ur code y'day, it worked fine on my computer too. The only changes I did I changed everything to DP, and For checkpoint I added webelement to OR and removed the property innertext which is keep changing dynamically right. So it is working fine. Mine is vista, QTP 10,IE8. Here is my code

Option Explicit ' Forces the definition using the Dim statement for all variables
Dim vLoan, vTerm, vRate ' Not mandatory to define variables, however it is a good practice
Dim br_op, mc_op
Dim vIter
Dim br_com, mc_org

' open browser

' Repeat x number of times/ ITERATE X NUMBER TIMES
For vIter  = 1 to 2

' Parameters can change values
vLoan = "350000"
vTerm = inputbox("Enter Term of the Loan")
vRate = "4"
'msgbox vLoan & vTerm & vRate
print vLoan & vTerm & vRate

' Application 1 : Bankrate.com
Set br_com = browser("name:=Mortgage Calculator - Bankrate.com").page("Title:=Mortgage Calculator - Bankrate.com") ' Ref or shortcut to the page
br_com.WebEdit("html id:=ctl00_well_DefaultUC_loanAmount").Set vLoan
br_com.WebEdit("html id:=ctl00_well_DefaultUC_nrOfYears").Set vTerm
    br_com.WebEdit("html id:=ctl00_well_DefaultUC_interestRate").Set vRate
    br_com.WebList("html id:=ctl00_well_DefaultUC_LoanMonth").Select "Jan"
br_com.WebList("html id:=ctl00_well_DefaultUC_LoanDate").Select "12"
br_com.WebButton("html id:=ctl00_well_DefaultUC_Calculate_1").Click

br_op = br_com.WebEdit("html id:=ctl00_well_DefaultUC_monthlyPayment").GetROProperty("value")
    print br_op

' Application 2: Mortgagecalculator.com
' Add objects to local, then write the logic
' Navigates to a different URL
browser("name:=Mortgage Calculator - Bankrate.com").Navigate "http://www.mortgagecalculator.org"

' Creates a blank object mc_org and puts a pointer to that specific page
Set mc_org = browser("Title:=Mortgage Calculator").Page("Title:=Mortgage Calculator") 

mc_org.WebEdit("name:=param\[principal\]").Set vLoan
mc_org.WebEdit("name:=param\[term\]").set vTerm
mc_org.WebEdit("name:=param\[interest_rate\]").Set vRate
mc_org.WebEdit("name:=param\[property_tax\]").Set "0"
mc_org.WebEdit("name:=param\[pmi\]").Set "0"
mc_org.WebButton("name:=Calculate").Click

' Synchronization points are aimed at synchronizing the object or app or bringing to a specific state before continuing
mc_org.Sync ' Sync will instruct QTP to wati for the mc_org page to get loaded before proceeding to next step
' wait 3 ' Diff with sync u dont know how long to wait. 

Browser("Mortgage Calculator").Page("Mortgage Calculator").WebElement("monthlypayment").output CheckPoint("Monthlypayment")
' browser("Title:=Mortgage Calculator").Page("Title:=Mortgage Calculator").Output CheckPoint("mcorg_op")
print environment("monthlypayment") ' To get value out of a environment variable
' msgbox mc_org.WebElement("payment").GetROProperty("outertext")

browser("Title:=Mortgage Calculator").Navigate "http://www.bankrate.com/calculators/mortgages/mortgage-calculator.aspx"
Next


Thanks

Sushma Jain

unread,
Dec 28, 2012, 5:03:25 PM12/28/12
to qtp-ele...@googlegroups.com, Sushma Jain
Hello Dinesh,

Thanks for the reply. Its really surprising that the application is working perfectly at your end. I wouldn't have reported the problem if it would have behaved the same with all other applications. I am attaching another zipped folder for your reference where application switch over takes place without using "Navigate" method and it successfully opens both the applications and outputs the result. Therefore I can't say that my IE and user control settings are wrong. These 2 settings I have completed according to instruction provided in the welcome pack, while installing QTP. However, I am not aware of any other settings are involved.

Regards,

Sushma
Mortgage_Calculator2.zip

Sushma Jain

unread,
Dec 28, 2012, 5:49:15 PM12/28/12
to qtp-ele...@googlegroups.com, Sushma Jain
Hello Dinesh,

I just searched some QTP forums and found the solution to this problem. In IE 9, in Manage ad-on option BHOManager class should be enabled. I just did it and now my application is working by inserting sufficient wait statement.

Thanks

Dineshkumar Rajendran

unread,
Dec 28, 2012, 6:16:32 PM12/28/12
to Sushma Jain, QTP eLearn Team
Hi Sushma,

Good to know this option. Thanks for update.

Thanks,
Dinesh

Jitendra.S

unread,
Jan 1, 2013, 9:54:38 PM1/1/13
to qtp-ele...@googlegroups.com, Sushma Jain
Sushma,

If still you are facing navigation issue ..You have to make changes...

Go to Setting (Setting icon on right side of IE )>>Manage add-ons>>Select Toolbars and extensions
>>Enable BHO manager class..

Then try it..Put 2 sec as wait ..Let me know..


~J~

Jitendra.S

unread,
Jan 1, 2013, 9:55:57 PM1/1/13
to qtp-ele...@googlegroups.com, Sushma Jain
For more setting I already posted this setting and many other setting .Could you please search and let us know..

~J~
Reply all
Reply to author
Forward
0 new messages