Micro Focus QTP (UFT) Forums
fing the string in web page - 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: fing the string in web page (/Thread-fing-the-string-in-web-page)



fing the string in web page - sia sharma - 08-22-2012

Hi All,

I have a string... for eg. "QTP Forum" in a variable 'A'
and i want to find that whether this string exists in a web page?

I have tried to do with 'InStr' function.
but it finds the string in another string.
i want to find the string in a web page....


Thanks,
sia


RE: fing the string in web page - Ankesh - 08-22-2012

@Sia,

There are three option that you can use for this.

1. You can use the find option on the webpage by using Ctrl+F. You can use the sendkey/Shell object.

2. Use a regular expression to check for this

3. Get the whole page text using
Code:
strBodyText=Browser().Page().Object.Body.innertext
'Now use instr function to see if the text was found or not
If Instr(strBodyText,"<Your Text>")>0 Then
'Found
Else
'Not Found
End IF

Regards,
Ankesh


RE: fing the string in web page - sia sharma - 08-22-2012

Hi,Ankesh
I m using 3rd logic and it works ... gr8 ...thanks

and also i would love to know how the second logic works
2) use of regular expression ?


RE: fing the string in web page - sia sharma - 09-12-2012

Hello All,

I have a script to find a string in a web page.
But my page contains the string at three different position with three different format.
i want to find the string with particular styling(format).

i got this error

Object doesn't support this property or method
Line (10):
Code:
"If Instr(strBodyText,val)>0 Then".

here is my code

Code:
strBodyText=Browser("Jsdl").Page("Jsda").Object.Body.innertext
dim val
set val=WebElement("html tag:=H1","innertext:="&DataTable("categories", dtGlobalSheet))

If Instr(strBodyText,DataTable("categories", dtGlobalSheet))>0 Then
Reporter.ReportEvent micPass,"pass","category found 1"
Browser("Jsdl").Page("Jsdl").WebElement("html tag:=H1","innertext:="&DataTable("categories", dtGlobalSheet)).click
else
Reporter.ReportEvent micFail,"invalid","category not found"
End If

why this error is occuring?

thanks
sia


RE: fing the string in web page - Ankesh - 09-12-2012

below statement is wrong

Code:
set val=WebElement("html tag:=H1","innertext:="&DataTable("categories", dtGlobalSheet))

you should use

Code:
Set val=Browser().Page().Webelement()

Now val becomes an object. You can not directly compare its value to a string. Use val.text instead.

I dont see the code for which you have got the error in the code you have posted. Plz post the full code.

Regards,
Ankesh