You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用UFT/QTP控制Chrome缩放且不新建实例修改测试页面级别

Hey there! Let's tackle your two UFT/QTP Chrome zoom questions one by one—here are practical, tested solutions that work without needing to spin up new browser instances:

1. Implement Zoom In/Out for Chrome in UFT/QTP

Chrome relies on native keyboard shortcuts for zoom controls, and UFT can simulate these easily. This method mirrors the exact behavior you'd get manually pressing Ctrl++ or Ctrl+-:

Using Keyboard Shortcuts (Native Browser Zoom)

This affects the entire browser window's zoom level, just like manual interaction:

' First, ensure the Chrome browser window is active
Browser("title:=.*").Activate

' Zoom In (Ctrl + Plus sign)
Browser("title:=.*").Page("url:=.*").WebElement("tagname:=html").SendKeys "^+"

' Zoom Out (Ctrl + Minus sign)
Browser("title:=.*").Page("url:=.*").WebElement("tagname:=html").SendKeys "^-"

' Reset zoom to 100% (Ctrl + 0)
Browser("title:=.*").Page("url:=.*").WebElement("tagname:=html").SendKeys "^0"

Pro Tips:

  • Replace the title:=.* and url:=.* with your actual browser/page identifiers for better reliability.
  • Targeting the <html> element ensures the keystrokes are sent to the entire page, not just a single input field.

Alternative: JavaScript-Based Page Zoom

If you need to set an exact zoom percentage (instead of incremental steps), you can run a JavaScript snippet directly on the page. Note this modifies the page's CSS zoom, not the browser's native zoom setting:

' Set zoom to 120%
Browser("title:=.*").Page("url:=.*").RunScript "document.body.style.zoom = '120%'"

' Set zoom to 80%
Browser("title:=.*").Page("url:=.*").RunScript "document.body.style.zoom = '80%'"
2. Modify Zoom Level of an Active Chrome Instance (No New Browser)

The best part? Both methods above work directly on your existing, test-running Chrome instance—no need to launch a new browser window. Here's how to make it seamless:

  • Keep your existing Browser/Page objects: You don't need to call Browser("Chrome").Launch again. Just reference the same browser instance you're already using for your test.
  • Use the keyboard shortcut method for native zoom: This will adjust the zoom level of the active tab/window without disrupting your test flow.
  • For exact percentages: Use the JavaScript snippet on your current Page object to set the zoom instantly.

Example Workflow:

' Assume you already have an active Chrome session from your test
Set currentBrowser = Browser("title:=My Test Page")
Set currentPage = currentBrowser.Page("url:=https://my-test-site.com")

' Adjust zoom to 110% incrementally
currentPage.WebElement("tagname:=html").SendKeys "^+" ' Zoom in once (usually ~10% step)

' Or set exact zoom via JS
currentPage.RunScript "document.body.style.zoom = '110%'"

内容的提问来源于stack exchange,提问作者deepthi cherukuri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:07:22