QTP如何检查WEB对象是否隐藏
在WEB页面中隐藏对象的3种方式
1、使用display
例如:
<label id="hiddenMessageDisplay" style="color:blue">This message is hidden using CSS display property</label>
<input onclick="if(this.value=='Show message'){this.value='Hide message';document.getElementById('hiddenMessageDisplay').style.display=''}else{this.value='Show message';document.getElementById('hiddenMessageDisplay').style.display='none'}" name="btnhiddenMessageDisplay" type="button" value="Hide message" />
2、使用visibility
例如:
<label id="hiddenMessageVisibility" style="color:red;">This message is hidden using CSS visibility property</label>
<input onclick="if(this.value=='Show message'){this.value='Hide message';document.getElementById('hiddenMessageVisibility').style.visibility=''}else{this.value='Show message';document.getElementById('hiddenMessageVisibility').style.visibility='hidden'}" name="btnhiddenMessageVisibility" type="button" value="Hide message" />
3、使用class
例如:
<label id="messageClass" name="btnmessageClass" type="button" value="Hide message" />
?
解决办法
1、针对第一种方式
方法(1):
Set oElm = Browser("B").Page("P").WebElement("This message is hidden using CSS display property")
If oElm.object.currentStyle.display="none" Then
Msgbox "Object is hidden"
Else
Msgbox "Object is visible"
End if
方法(2):
Set oElm = Browser("B").Page("P").WebElement("This message is hidden using CSS display property")
Dim x,y, width, height
x = oElm.GetROProperty("x")
y = oElm.GetROProperty("y")
width = oElm.GetROProperty("width")
height = oElm.GetROProperty("height")
If x=0 And y=0 And width=0 And height=0 Then
Msgbox "Object is hidden"
Else
Msgbox "Object is visible"
End if
方法(3):
Set oElm = Browser("B").Page("P").WebElement("This message is hidden using CSS display property")
If InStr(oElm.GetROProperty("attribute/style"),"display:none") Then
Msgbox "Object is hidden"
Else
Msgbox "Object is visible"
End if
2、针对第二种方式
采用类似方法(1)和方法(3)来处理
3、针对第三种方式
采用类似方法(1)来处理
方法(4):
Set oElm = Browser("B").Page("P").WebElement("This message is hidden using CSS display property")
If oElm.GetROProperty("class") = "messageHidden" Then
Msgbox "Object is hidden"
Else
Msgbox "Object is visible"
End if