Re: Error occuring while comparing values taken from database with the available webpage elements (21 Views)
Reply
Frequent Advisor
Anchal vaish
Posts: 49
Registered: ‎12-16-2009
Message 1 of 12 (21 Views)
Accepted Solution

Error occuring while comparing values taken from database with the available webpage elements

Hello Everyone,

I have pulled out a value from database and store that value in a variable (say Rs2).Now I am checking wheather this element value (HTML SPAN tag element) is present on a webpage or not using the below code.

Set Obj1=Browser("Google").Page("TATA COMMUNICATONS | CUSTOMER").Frame("workspaceBodyFrame_3").Object
Set Obj2=Obj1.getElementsByTagName("SPAN")
Rs=Obj2.length
Msgbox ("Total number of HTML elements found:" &Rs)
Do While ( z <= (Rs - 1))
z=z+1
Set Match_Text3=Obj2.item(z)
Match_Value3=Match_Text3.innerhtml
If (Match_Value3="&Rs2") Then
Msgbox ("OUT Total Text value found")
Exit Do
End if
Loop

Correction seems to be required in the above code because the element value is present
on the web page but still if statement does not execute.
All kind of suggestions are welcome.

Thanks & regards
Anchal vaish
Please use plain text.
Honored Contributor
Cody Marcel
Posts: 1,039
Registered: ‎02-27-2008
Message 2 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

My guess would be that the innerhtml is different that what you are comparing "&Rs2"

Add a print statement for the values. This way you can see all values to figure out why the compare fails. You also might want to try adding a trim() around the compare text.

print "Comparing ("& Match_Value3 & ")"
If (Match_Value3="&Rs2") Then
Msgbox ("OUT Total Text value found")
Exit Do
End if
Please use plain text.
Frequent Advisor
Anchal vaish
Posts: 49
Registered: ‎12-16-2009
Message 3 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

Thank you Cody Marcel.
I am checking it right away and will be sharing the outcome in few minutes with you.
Please use plain text.
Honored Contributor
Rhonda Robinson
Posts: 3,159
Registered: ‎11-13-2007
Message 4 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

I believe this line is incorrect:
If (Match_Value3="&Rs2") Then

1) The use of a single = is used to set a value, not to compare a value. Try using ==
2) "&Rs2" will be recognized as a string since it is in quotation marks rather than the value of the variable Rs2. Remove the quotes and the &

Resulting corrected line is:
If (Match_Value3==Rs2) Then
Please use plain text.
Honored Contributor
Cody Marcel
Posts: 1,039
Registered: ‎02-27-2008
Message 5 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

[quote]
If (Match_Value3="&Rs2") Then

1) The use of a single = is used to set a value, not to compare a value. Try using ==
2) "&Rs2" will be recognized as a string since it is in quotation marks rather than the value of the variable Rs2. Remove the quotes and the &

Resulting corrected line is:
If (Match_Value3==Rs2) Then
[/quote]

Sorry Rhonda, but this is not correct. What you say is true in other languages such as Java or C, but in VBScript the "=" is used for both assignment and equality checks depending on the context. The "==" operator has not meaning in VBScript.
Please use plain text.
Frequent Advisor
Anchal vaish
Posts: 49
Registered: ‎12-16-2009
Message 6 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

Hello to Both of you.

As per cody suggestion, I am trying print statement but here is one question
code that cody provided is below

print "Comparing ("& Match_Value3 & ")"

which uses syntax like : "& Match_Value3 & "

so shall i try with the below change code too?....

If (Match_Value3="&Rs2&") Then

Thanks
Please use plain text.
Honored Contributor
Cody Marcel
Posts: 1,039
Registered: ‎02-27-2008
Message 7 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

I added some comments.

' This prints the value of the Match_Value3 variable.
print "Comparing ("& Match_Value3 & ")"

'This checks to see if the value of Match_Value3 is equal to "&Rs2&". You want the exact value inside "&Rs2&" to match Match_Value3
If (Match_Value3="&Rs2&") Then



=====================
Do not be confused by the & inside out side the quotes. Everything inside "" is a string literal. outside the "" & has a special meaning in VBScript that concatenates strings together. If you are still confused, paste the output of that print statement when you run.
Please use plain text.
Frequent Advisor
Anchal vaish
Posts: 49
Registered: ‎12-16-2009
Message 8 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

Innerhtml is not different. I checked using print statement as well.

For time being, I provide Rs2 input using inputbox function.

Set Obj1=Browser("Google").Page("TATA COMMUNICATONS | CUSTOMER").Frame("workspaceBodyFrame_3").Object
Set Obj2=Obj1.getElementsByTagName("SPAN")
Rs=Obj2.length
Msgbox ("Total number of HTML elements found:" &Rs)
Rs2=Inputbox("Enter OUT Traffic value:") 'Enter value 1,720,071

Do While ( z <= (Rs - 1))
z=z+1
Set Match_Text3=Obj2.item(z)
Match_Value3=Match_Text3.innerhtml
print "Comparing ("& Match_Value3 & ")" 'Part of print statement:
If (Match_Value3="&Rs2") Then
Msgbox ("OUT Total Text value found")
Exit Do
End if
Loop

Part of print statement:
Comparing (Total )
Comparing (850,274 )
Comparing (1,720,071 )
Comparing (Page 50 of 50 )

Thanks
Please use plain text.
Honored Contributor
Cody Marcel
Posts: 1,039
Registered: ‎02-27-2008
Message 9 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

[quote]
Rs2=Inputbox("Enter OUT Traffic value:") 'Enter value 1,720,071

Do While ( z <= (Rs - 1))
z=z+1
Set Match_Text3=Obj2.item(z)
Match_Value3=Match_Text3.innerhtml
print "Comparing ("& Match_Value3 & ")" 'Part of print statement:
If (Match_Value3="&Rs2") Then
Msgbox ("OUT Total Text value found")
Exit Do
End if
Loop

Part of print statement:
Comparing (Total )
Comparing (850,274 )
Comparing (1,720,071 )
Comparing (Page 50 of 50 )
[/quote]

I see your problem now. Rs2 is a variable and you are comparing it as if it were a string literal. Change to this

print "Comparing ("& Match_Value3 & ") to (" & Rs2 & ")"
If (Match_Value3=Rs2) Then
Msgbox ("OUT Total Text value found")
Exit Do
End if

If this does not work, please paste the entire print output.
Please use plain text.
Frequent Advisor
Anchal vaish
Posts: 49
Registered: ‎12-16-2009
Message 10 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

Sorry, I can't continue for today anymore.
Tommorow I will see to this matter with a fresh mind.

Thanks cody for your kind suggestions.
Anchal vaish


Please use plain text.
Occasional Visitor
Benoy S
Posts: 4
Registered: ‎01-25-2010
Message 11 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

Hi Anchal,

If you are taking the parameter from the database as a string, you can use StrComp or InStr function within the if loop to compare the values of Match_Value3 and Rs2. StrComp returns 0 if Match_Value3 equals Rs2.

If (StrComp(Match_Value3, Rs2) = 0) Then
Msgbox...
..
Loop

And InStr returns 1 if Match_Value3 equals Rs2

Thanks,
Benoy S
Please use plain text.
Frequent Advisor
Anchal vaish
Posts: 49
Registered: ‎12-16-2009
Message 12 of 12 (21 Views)

Re: Error occuring while comparing values taken from database with the available webpage elements

Hello All,

Cody 10 out of 10 for your help and your shared views on my mistakes
have been worthy for me.Your latest suggestion worked.

Thanks to Benoy & Rhonda as well.

Regards
Anchal vaish
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation