Micro Focus QTP (UFT) Forums
help about CreateObject - 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: help about CreateObject (/Thread-help-about-CreateObject)

Pages: 1 2 3


help about CreateObject - stevol - 05-29-2008

Hi,
I would create a function only to open a website, but out of function I must do some operation on the site. How can I write the code?

Code:
Function Open()
   Dim ObjExplorer
   Set ObjExplorer = createobject("InternetExplorer.Application")
   ObjExplorer.visible=true
   ObjExplorer.navigate"http:\\www.google.it"
End Function
Open
... if here I write ObjExplorer.Page("..") obviously fails for the lack of the object in the repository.
Somebody can write me some code row so i can understand the exact procedure way?

thanks for every help!


RE: help about CreateObject - Ankur - 05-29-2008

so you have eliminated the need for using methods like systemutil.run and Invoke Application....you are on a right track...
Start recording your script now, that's why QTP is there for Smile

You can read more about Internet Explorer Automation Object Model here... http://msdn.microsoft.com/en-us/library/ms970456.aspx


RE: help about CreateObject - stevol - 05-30-2008

mmhhh... I have found the solution for my answer, that is:

Code:
Function Open()
  dim objexplorer
  set objexplorer     = CreateObject("InternetExplorer.Application")
  objexplorer.visible = true
  objexplorer.navigate "http://www.google.it"
  set Open = objexplorer
  Set objexplorer = nothing
End Function

Dim IEexp, testo
set IEexp = Open()
testo = IEexp.statustext
msgbox testo

Now my problems continue with QTP, about relationships. My goal is something similar to:
Browser("...").Page("...").WebEdit("...").Set "xyz"
but without objects in the O.R.  I obtain error with this code:

Code:
dim objexplorer, pagina, pagina2
set objexplorer     = CreateObject("InternetExplorer.Application")
objexplorer.visible = true
objexplorer.navigate "http://www.google.it"
Set pagina = description.Create()
pagina("Class Name").value= "Page"
Set pagina2= objexplorer.childobjects(pagina)
...

Where do I wrong?
thanks for every help

PS: the link "https://www.learnqtp.com/descriptive-programming-simplified/" is useful but not still sufficient exhaustive for my lacks :-)


RE: help about CreateObject - Ankur - 05-30-2008

so you have problem writing Descriptive Programming... I think the very 1st point of this post on Descriptive Programming and QTP (the one you have mentioned above) covers it all...and yes it is exhaustive also for the question you have put up...probably you need to read more carefully...

ok... will clarify once again...we will take the example from that post only...

Code:
Browser(“Browser”).Page(“Page”).WebRadioGroup(“Name:=txt_Name”,”html tag:=INPUT”).set “Test”

This example combines Object Repository(OR) and Descriptive Programming(DP) approach...that first two objects Browser and Page use OR and the last one WebRadioGroup use DP.

Now how to write DP? You need to find the unique property-value pair(s) [In the example above Name is property and txt_Name is its value similarly tag is property and INPUT is its value ]from the set of properties mentioned when you object spy on an object... an easier approach is to first record and find the unique properties QTP is using, then use the same property-value pair(s) for your DP code to identify the objects.

Similarly, you can extend this approach to Browser and Page objects.


RE: help about CreateObject - anemuday - 07-17-2008

Hi stevol,

I tried the samething longtime back, and here is my script:
Code:
systemutil.Run "iexplore.exe","http://www.mail.yahoo.com"
browser("title:=Yahoo.*").page("title:=Yahoo.*").webtable("name:=login.*").webedit("name:=login","html tag:=INPUT").set "xyz"
browser("title:=Yahoo.*").page("title:=Yahoo.*").webtable("name:=login.*").webedit("name:=passwd","html tag:=INPUT").set "abc"
browser("title:=Yahoo.*").page("title:=Yahoo.*").webbutton("name:=Sign In").click

Even you use Descriptive Programming, to know the object properties use Object Spy and write the script.

Let me know, if you have any problems in the above script.

Thanks & Regards,
Uday.


RE: help about CreateObject - vineet1234 - 01-08-2009

Hi Uday,
I think your script should be
Code:
browser("name:=Yahoo.*").page("title:=Yahoo.*").webtable("name:=login.*").webedit("name:=login","html tag:=INPUT").set "xyz"  ,
since qtp uses "name" property of browser class to uniquely identify the browser object.

And Stevol, why do you want to re-do something which is already available in QTP??
Just like your function Open() now returns a reference to the IE application opened(by the function itself),
now you should find some way of getting reference to collection of objects displayed on the web page opened by the function Open(). Is it worth it??


RE: help about CreateObject - stevol - 01-13-2009

Hi,
my aim was to use a function to create an IE object, then identify hwnd property to send it to the calling script for other functions. The use of runutility ie.explore is not exactly right for me, because my browser must have a certain website pre-imposted, so if i had already opened a browser and i wanted to open another browser, with runutility i would have problems to recognize new browser (i use the name/title property to recognize the browser). Howewer, I have found the solution with a function like this:

Code:
Function FunOpenBrowser()
    
    dim objexpl, brow, pag, hwnd(1)
    set objexpl = CreateObject("InternetExplorer.Application")
    objexpl.visible = true
    objexpl.navigate "http://www.google.it"
    wait(5)
    
    Set brow  = Browser("hwnd:=" & objexpl.hwnd)
    Set pag   = brow.Page("title:=" & objexpl.Document.Title)
    brow.sync
    wait(5)

    hwnd(0)  = brow.getroproperty("hwnd")
    hwnd(1)  =  pag.getroproperty("hwnd")
    
    Reporter.ReportEvent 0, "FunOpenBrowser", "hwnd browser: " & hwnd(0) & vbcr & "  hwnd page: " & hwnd(1)
    
    FunOpenBrowser = hwnd
    
    Set objexpl = nothing
    
End Function

bye


RE: help about CreateObject - SUSHEEL_VIG - 07-26-2009

Hi Ankur,

I am using Web, ActiveX and Terminal emulator for my test.
I have two main problems:
1.) When I run my test on a new cics session the recorded test case can not find the object TeScreen("screen28888").TeField("field167") etc. on a new cics session but no problem on already opened. the screen and field no. are dynamic and get changed with each new CICS session.

2.) I have the same problem with my web test as name of our portal web changes every time you open a new internet browser and QTP can not find the already recorded object.

There is no problem if I run the recorded test on already opened host terminal or web session where I recorded the test.

How do I solve this problem?


RE: help about CreateObject - tkmseie - 11-19-2009

Hi..
While opening a new browser the browser instance value will get increased.If you compare any object name in first and second browser you can find which value get increased. Assign a variable for that value every time increase or decrese that value for opening or closing the browsers.

Or Try to use regular expression symbols like "daf*" for those values

Thanks


RE: help about CreateObject - rajpes - 07-30-2011

ashy
Dont post your questions in existing threads, create a new one with appropriate title