【问题标题】:How do I access the Title attribute value of an Input field with Cypress.io?如何使用 Cypress.io 访问 Input 字段的 Title 属性值?
【发布时间】:2019-03-04 16:17:01
【问题描述】:

我正在尝试 POST 到一个表单,其值包含在输入字段的标题属性中:

<input type="text" id="dynamicStationID" class="stationNameInput" value="Station 1" title="Station 25696" />

在上述情况下,我想从 title 属性中提取数字 25696,然后构建我的 POST:

cy.request({
method: 'POST',
url: 'https://staging/api/rest/robots.cfm',
form: true,
body: {
  stationName: 'Station 1',
 stationID: '25696' }

我似乎无法理解如何获取该值并将其插入 POST 正文。

【问题讨论】:

    标签: mocha.js chai cypress


    【解决方案1】:

    通过更多研究,我能够弄清楚:

    cy.get("input.stationNameInput").then(elem => {
       let score=elem.attr("title").slice(4);
    })
    

    这得到了我可以在我的 POST 中使用的数字 25696。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多