Micro Focus QTP (UFT) Forums
Dynamic Webelement Value - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Dynamic Webelement Value (/Thread-Dynamic-Webelement-Value)



Dynamic Webelement Value - Novemberrain81 - 08-26-2013

Hello all. I am trying to work on a practice project.
I am working with finance.yahoo.com I have the following code
Code:
systemutil.Run "iexplore.exe","finance.yahoo.com"

Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("html tag:= INPUT","type:=text","name:=s","value:=Enter Symbol").Set "NFLX"

Browser("micclass:=Browser").Page("micclass:=Page").WebButton("html tag:= INPUT","name:= Look Up","type:= Submit","Value:=Look Up","html id:=btnQuotes").Click

After this I am trying to get the outertext value from the Last Closing Price, which is an webelement and the biggest text size.
Now my questions...if the webelements dynamic I can get the value using hard coded property values. However I have a whole bunch of stock symbols I am reading in from excel which is within a for loop. And the required property values for the webelement chages with every iteration of the for loop. So how do I deal with this?
Webtable will not work as this webelement is not within a webtable. If it was, I would simply use getcelldata.
I am also attaching a file with a little description.
PS I am practice with Static Descriptive programming as of right now.
Thank you in advance for any help.


RE: Dynamic Webelement Value - GregHicks - 08-26-2013

hi

thanks for posting your code and your problem with the screen that you are working with.

A suggestion to help resolve dynamic fields is to use the object inspector to probe the objects, you may discover that there is a consistent property that can be used. Would you mind trying that and sending the screen grab so we can engage on the properties in the object?

hear from you soon.


RE: Dynamic Webelement Value - Parke - 09-30-2013

novemberrain81:

'' using finance.yahoo.com
' You needed to look in the source code.

Code:
' the field appears to have an html id value = "yfs_l84_symbol", where symbol is nflx, ibm or....
'symbol = "IBM"
symbol = "NFLX"
browserName = symbol&": .*"
pageTitle = symbol&": .*"

Set oDesc =description.Create()
oDesc("micclass").value = "WebElement"
oDesc("html tag").value = "span"
oDesc("html id").value = "yfs_l84_"&LCase(symbol)

Set oAll = browser("name:="&browserName).page("title:="&pageTitle).childObjects(oDesc)
cnt = oAll.count
print "count = " & cnt

For  i = 0 to oAll.count - 1
    'If oAll.item(i).GetROProperty("html id") = "yfs_l84_nflx" Then
    If oAll.item(i).GetROProperty("html id") = "yfs_l84_"&LCase(symbol) Then
        print oAll.item(i).GetROProperty("html id") & " :: " & oAll.item(i).GetROProperty("outertext")
    End If
    'print oAll.item(i).GetROProperty("html id") & " :: " & oAll.item(i).GetROProperty("outertext")
Next

Results:
count = 1
yfs_l84_ibm :: 186.13
count = 1
yfs_l84_nflx :: 309.17
hth,

Parke