使用IE对象打开被测网址,并设置浏览器全屏
上一篇 /
下一篇 2013-05-30 16:32:28
/ 个人分类:QTP自动化笔记
VBS获取屏幕分辨率
(1)获取屏幕的分辨率(除去windows任务栏)
方法一:
'==============================================
'创建htmlfile对象
set dom = CreateObject("HtmlFile")
'获取屏幕的宽度(除去windows任务栏)
width = dom.ParentWindow.Screen.AvailWidth
'获取屏幕的高度(除去windows任务栏)
height = dom.ParentWindow.Screen.AvailHeight
Set dom = Nothing
方法二:
'=============================================
Set ie = CreateObject("internetexplorer.application")
ie.navigate "about:blank"
Do
Loop Until ie.ReadyState = 4 '等待页面完全加载完全
'获取屏幕的高度(除去windows任务栏)
Height = ie.Document.parentwindow.screen.availHeight
'获取屏幕的宽度(除去windows任务栏)
Width = ie.Document.parentwindow.screen.availWidth
Set ie = Nothing
(2)获取屏幕的分辨率(包括windows任务栏)
方法一:
'==============================================
'创建htmlfile对象
set dom = CreateObject("HtmlFile")
'获取屏幕的宽度(包括windows任务栏)
total_width = dom.ParentWindow.Screen.Width
'获取屏幕的高度(包括windows任务栏)
total_height = dom.ParentWindow.Screen.Height
Set dom = Nothing
方法二:
==============================================
'创建浏览器对象
Set ie = CreateObject("internetexplorer.application")
'打开空页面,这里也可以输入其他的网址
ie.navigate "about:blank"
'等待页面完全加载完全
Do
Loop Until ie.ReadyState = 4
'获取屏幕的高度(包括windows任务栏)
Height = ie.Document.parentwindow.screen.Height
'获取屏幕的宽度(包括windows任务栏)
Width = ie.Document.parentwindow.screen.Width
Set ie = Nothing
结合以上方法我们在QTP的的代码编写中,可以使用以下函数打开测试网址,并设置当前浏览器界面全屏(如果不全屏会影响qtp运行时对象的识别),此函数可以作为公共函数使用
'******************************************************
'功能:使用IE浏览器打开被测网站,并设置当前浏览器全屏显示
'参数:URL - 需要代开的被测网址
' TimeOut- 网站打开等待的超时时间(单位:秒)
'******************************************************
Sub openURL(URL,TimeOut)
'创建ie对象
Set IE = CreateObject("internetexplorer.application")
'创建htmlfile对象
Set Dom = CreateObject("Htmlfile")
'打开指定的URL
IE.Navigate URL
StartTime = Now
'等待网站打开,若等待超时或在指定的超时时间内打开,则退出循环
Do
LoadTime = DateDiff("s",StartTime,now)
Loop Until (IE.ReadyState = 4 or LoadTime >= TimeOut)
'设置浏览器全屏
With IE
'设置浏览器距屏幕左边距离为0
.Left = 0
'设置浏览器距屏幕右边距离为0
.Top = 0
'设置浏览器的高度与屏幕高度一致(除windows去任务栏)
.Height = Dom.parentwindow.screen.availHeight
'设置浏览器的宽度与屏幕宽度一致(除windows去任务栏)
.Width = Dom.parentwindow.screen.availWidth
'设置浏览器可见
.Visible = True
End With
Set Dom = Nothing
Set IE = Nothing
End Sub
收藏
举报
TAG:
全屏
ie
IE
QTP
qtp