Nila
Nila

Reputation: 11

QTP webelement check not executing "else" condition

I am trying to validate if a webelement property exists on the page or not. But QTP always returns true :( and not going to 'Else' part . Below is my code. pls help to fix this :(

BlnResult = Browser("CDMS :: Master Agreement").Page("CDMS :: Master   Agreement").WebElement("File Upload successfully").Exist(0) Then 
 Msgbox "Success"
 Else 
 Msgbox "Fail"
 End If

QTP always returns "success" even in case if web element doesn't exist on the page.

Upvotes: 0

Views: 367

Answers (1)

vins
vins

Reputation: 15390

As 'TheBlastOne' mentioned, Exist method does not check if the element is visible or not. Even if it is hidden using CSS, it will still return TRUE.

So, Try something like this. (Here we check element coordinates. If it is present in the UI, they will have some coordinates. Not 0)

Set FileUpload = Browser("CDMS :: Master Agreement").Page("CDMS :: Master   Agreement").WebElement("File Upload successfully")

If FileUpload.GetROProperty("x") <> "0" AND FileUpload.GetROProperty("y") <> "0" Then 
      Msgbox "Success"
Else 
      Msgbox "Failed"
End If

Upvotes: 1

Related Questions