如何在使用 UFT/QTP 时放大或缩小网页 [英] How to Zoom in or Zoom out in a webpage while using UFT/QTP

查看:24
本文介绍了如何在使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆