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

如何在Katalon Recorder中将验证码存储到verfcode变量?

把验证码存入verfcode变量的操作方法

场景一:前端页面获取用户输入的验证码

如果是在网页里拿到用户输入的验证码,用JavaScript实现:

  • 先定位验证码输入框(比如通过输入框的id)
  • 把输入框的内容直接赋值给verfcode变量

代码示例:

// 假设验证码输入框的id为"verification-code"
const verfcode = document.getElementById('verification-code').value;
// 可打印验证变量内容
console.log(verfcode);

场景二:爬虫/后端自动识别验证码图片

要是需要自动识别验证码图片内容并存入变量,用Python实现的步骤:

  1. 请求获取验证码图片的内容
  2. 用OCR工具(如pytesseract)识别图片中的文字
  3. 将识别结果存入verfcode变量

代码示例:

import requests
import pytesseract
from PIL import Image
from io import BytesIO

# 替换为实际的验证码图片地址
captcha_url = "https://xxx.com/captcha.jpg"
# 请求获取图片资源
resp = requests.get(captcha_url)
# 读取图片
img = Image.open(BytesIO(resp.content))
# 识别验证码并去除多余空格换行
verfcode = pytesseract.image_to_string(img).strip()
# 查看变量内容
print(verfcode)

场景三:手动输入验证码存入变量

如果需要用户手动输入验证码,直接通过输入函数将内容存入变量:

# Python示例
verfcode = input("请输入验证码:")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 17:51:13