使用UFT/QTP时如何放大或缩小网页 [英] How to Zoom in or Zoom out in a webpage while using UFT/QTP
问题描述
我想使用UFT控制被测应用程序的网页的放大和缩小功能.这是必需的,因为缩放级别会动态变化,并且很难识别对象. 我找到了一个代码,但是如果您需要在一个实例或开始时更改缩放级别,它会很有用.下面是代码
I would like to control the zoom in and out feature of my webpage of the application under test using UFT. This is required as the zoom level changes dynamically and it becomes difficult to identify the objects. I have found a code but it is useful if you need to change the zoom level at one instance or at the start. below is the code
Function ChangeIEZoom
Dim intZoomLevel, objIE
intZoomLevel = 110
Const OLECMDID_OPTICAL_ZOOM = 63
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate ("www.google.com")
While objIE.Busy = True
wait 5
Wend
objIE.ExecWB OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(intZoomLevel), vbNull
End Function
使用此代码,它将打开一个新的浏览器并将其导航到URL.
with this code, it opens up a new browser and navigates it to a URL.
我不希望它创建浏览器的新实例. 我需要的是它会更改已经在测试执行中的同一页面上的缩放级别,也需要更改缩放级别的页面在开始时就不知道,并且基于识别出的事实它可能会或可能不需要更改某些对象.
I do not want it to create a new instance of the browser. What I need is that it changes the zoom level on the same page which is already under test execution, also the page where zoom level change is required not known at the start and it may or may not require change based on the fact that it identifies certain objects.
有人遇到过相同的问题或有解决方案吗?
Has anyone faced the same issue or has a solution to it ?
推荐答案
我找到了一个解决方案-结合您在评论中提到的内容.如果您要更改当前正在处理的网页的缩放级别,则此方法有效.当您想在多个实例上进行放大和缩小时会提供帮助
I found a solution - combining what you mentioned in comments. this works if you want to change the zoom level on current webpage you are working on. helps when you want to zoom in and out at multiple instances
Dim ShellApp
Set ShellApp = CreateObject("Shell.Application")
Dim ShellWindows
Set ShellWindows = ShellApp.Windows()
Dim intZoomLevel
intZoomLevel = 110
Const OLECMDID_OPTICAL_ZOOM = 63
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Dim i
For i = 0 To ShellWindows.Count - 1
If InStr(ShellWindows.Item(i).FullName, "iexplore.exe") <> 0 Then
Set IEObject = ShellWindows.Item(i)
End If
If IEObject.Visible = True Then
While IEObject.Busy = True
wait 5
Wend
IEObject.ExecWB OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(intZoomLevel), vbNull
End If
Next
print "it works"
这篇关于使用UFT/QTP时如何放大或缩小网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!