LoadRunner[WEB HTTP]脚本问题:动态值关联捕获与响应页面显示异常
Hey Raj, let's tackle your two LoadRunner [WEB HTTP] scripting issues one by one:
Problem 1: Capturing the Target Dynamic Value Without Multiple Matches
I get it—your original boundary-based extraction pulls too many results because the left/right boundaries (||~1fc~ and ||collaborator_role) are generic enough to show up in multiple places in the response. The fix here is to use a regular expression that locks onto the unique dynamic prefix (tcollaborators7c0202c71508 and its variants) to narrow down the exact string you need.
Here's how to set it up with web_reg_save_param_ex:
web_reg_save_param_ex( "ParamName=TargetCollaboratorValue", "REGEX=.*tcollaborators[0-9a-f]+\\|\\|~1fc~-([0-9a-f]+)\\|\\|collaborator_role", "SEARCH_FILTERS=ResponseBody", LAST);
Let me break this down:
tcollaborators[0-9a-f]+: Matches the dynamic prefix (since it's alwaystcollaboratorsfollowed by a string of hex characters).\\|\\|: Escapes the vertical bars (they're special characters in regex, so we need double backslashes because LoadRunner uses C-style string escaping).([0-9a-f]+): Captures the target hex value (your7ffdce2b/7ffdce0fstring) into the parameterTargetCollaboratorValue.
This regex will only match the exact string pattern you care about, eliminating unwanted multiple matches.
Problem 2: Getting a Full Page View Like the Recording Snapshot
LoadRunner's default response view often skips non-HTML resources (like CSS, JS, images) which makes the page look incomplete. Here are a few ways to replicate that full recording snapshot experience:
Enable full resource download in Run-Time Settings
- Open your script's
Run-Time Settings(press F4). - Navigate to
Internet Protocol > Preferences. - Check
Download non-HTML resources, then clickSettingsand ensure all resource types (images, stylesheets, scripts, etc.) are checked. - Also check
Simulate browser cacheto mimic how a real browser loads resources, which helps render the page correctly.
- Open your script's
Mimic real browser request headers
Some servers return stripped-down content if they detect a non-browser client. Add this header before your request to match what your recording browser sent:web_add_auto_header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");Adjust the value to match the
Acceptheader from your recording (you can find this in the Recording Log or Fiddler).Capture a rendered screenshot
If you want a visual snapshot, use theweb_save_screenshotfunction right after the request that returns the page:web_save_screenshot("FullPageSnapshot.png", LAST);After running the script, you'll find the PNG file in your script's directory—this shows the page as it would render in a browser.
Use Fiddler for detailed page inspection
Set LoadRunner to route traffic through Fiddler:- In
Run-Time Settings > Internet Protocol > Proxy, checkUse proxy serverand enter127.0.0.1as the address,8888as the port. - Run Fiddler, then run your script.
- In Fiddler, find the response you care about, double-click it, and switch to the
WebViewtab—this gives you a fully rendered view of the page, just like your recording snapshot.
- In
内容的提问来源于stack exchange,提问作者Raj

