This is expected because when we create a reference to the object and use it for the first time, QTP cashes the object and maps it to the run time object.It does this cashing to improve performance on the same object when used later.But when the application state has changed(page refreshed or changed) these object references are no longer valid.So I would suggest you to get the reference again before you click.
This is how you would do it.
Code:
Set objlink = description.Create()
objlink("micclass").value ="Link"
set links = browser("title:=.*").Page("title:=.*").ChildObjects(objlink)
totalnooflinks = links.count
For i =0 to links.count -1
set links = browser("title:=.*").Page("title:=.*").ChildObjects(objlink)
links(i).click
browser("title:=.*").Back
Next
That's correct we cannot print a method action.The code returns general error though print is excluded in the second iteration as the reference is lost due to Browser().back.
Here is a small demo to justify this statement.
Code:
Set oPage=Browser("name:=Google").Page("title:=Google")
Set oSearch=oPage.WebEdit("name:=q")
Set oSearchButton=oPage.WebButton("name:=Search")
oSearch.Set "Learn QTP" 'runs fine without any error
Browser("name:=Google").Refresh 'or back..
oSearch.Set "Learn QTP" 'throws error
Each QTP object has a hidden method "Init" to reinitialize the object cashe. Using Init on the object makes sure that it is re-identified.With QTP 11, new method "RefreshObject" has been introduced.
Code:
Set oPage=Browser("name:=Google").Page("title:=Google")
Set oSearch=oPage.WebEdit("name:=q")
Set oSearchButton=oPage.WebButton("name:=Search")
oSearch.Set "Learn QTP" 'runs fine without any error
Browser("name:=Google").Refresh
oSearch.RefreshObject 'reinitializing the object 'oSearch'
oSearch.Set "Learn QTP New" 'runs fine without any error
In that case it should say, "Object could not be found" and not a General Run error. You may check the object's properties during runtime using the watch statement.
Anyways, I would wait for excellent pawan to revert back as to what solved the problem.
Basanth Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
(07-22-2013, 09:28 AM)ravi.gajul Wrote: This is expected because when we create a reference to the object and use it for the first time, QTP cashes the object and maps it to the run time object.It does this cashing to improve performance on the same object when used later.But when the application state has changed(page refreshed or changed) these object references are no longer valid.So I would suggest you to get the reference again before you click.
This is how you would do it.
Code:
Set objlink = description.Create()
objlink("micclass").value ="Link"
set links = browser("title:=.*").Page("title:=.*").ChildObjects(objlink)
totalnooflinks = links.count
For i =0 to links.count -1
set links = browser("title:=.*").Page("title:=.*").ChildObjects(objlink)
links(i).click
browser("title:=.*").Back
Next
Looks like the page is still not navigated to the next one and we are doing browser().back.Could you please add some more wait time ,more than 60 seconds and try again?This should work fine.Looks like we have a synchronization issue.To isolate between synchronization and code, could you run it in debug mode and check for 3- 5 links allowing sufficient time for the page navigation.Let me know your findings.
using wait property it works now plz help me if i want to click on perticular link one by one with same name then how to do I am attaching a picture in which links is present