【问题标题】:Jmeter Xpath and Regular expressionJmeter Xpath 和正则表达式
【发布时间】:2015-08-30 14:39:35
【问题描述】:

我只需要从下面的代码中提取 jsessionid 值 8969424C7F388504711149044AB03FE9

<input type="hidden" name="execution" value="e1s1" />
 <input type="hidden" name="_eventId" value="submit" />
 <a id="forgotP" href='forgotPassword?service=https%3A%2F%2Fbg-cn-host%3A8443%2Fcloudsolutions%2Fj_spring_cas_security_check%3Bjsessionid%3D8969424C7F388504711149044AB03FE9'>Forgot password?</a>
 <input class="btn-submit" name="submit" value="Log In

我尝试了以下选项,但没有成功

//*[starts-with(@href,'forgotPassword')]/substring-after(@href, 'jsessionid%3D')

substring-after(/@href, 'jsessionid%3D')

//*[@id='forgotP']/contains(substring-after(., 'jsessionid%3D'))

name="(.+)"\stype="hidden"value="(.+)"

需要 Xpath 和正则表达式

【问题讨论】:

  • 我试过这个 id="forgotP"\shref="(.3D+?)"\s*

标签: java regex xpath jmeter


【解决方案1】:

正确的 XPath 表达式应该是:

substring-after(//a[starts-with(@href,'forgot')]/@href,'jsessionid%3D')

如果您的响应不符合 XML/XHTML 标准,请确保选中“使用整洁(容错解析器)”框

您可以使用 View Results Tree 侦听器针对响应数据测试 XPath 表达式。

但是我相信你可以更轻松地做到这一点。鉴于 JSESSIONID 只是一个 cookie,它应该由HTTP Cookie Manager 完美处理,此外,众所周知,XPath Extractor 是资源密集型的,建议尽可能避免使用它。

  1. 将以下行添加到 user.properties 文件(位于 JMeter 安装的 /bin 文件夹下)

    CookieManager.save.cookies=true
    
  2. 重启 JMeter
  3. 将 HTTP Cookie 管理器添加到您的测试计划中
  4. 无论您在哪里需要 JSESSIONID 值,都可以使用 ${COOKIE_JSESSIONID} 变量

有关详细信息,请参阅Using the HTTP Cookie Manager 指南。

【讨论】:

    【解决方案2】:

    试试这个正则表达式,

    3Bjsessionid\%3D(\w+)'>Forgot password
    

    3Bjsessionid\%3D([0-9A-Z]+)'>Forgot password
    

    假设您知道 JMeter 中的正则表达式提取器,我不会提供 JMeter 正则表达式快照。对于 Xpath,我认为您的 Xpath 查询是正确的。

    【讨论】:

      猜你喜欢
      • 2016-12-26
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 2015-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      相关资源
      最近更新 更多