赛普拉斯 - 当它作为 space 时查找输入元素 ID?

Cypress - Finding input element id when it as a space in it?

我正在尝试通过其 ID 识别 iframe 中的输入元素(我正在使用“cypress-iframe”库来解决这个问题),以便我可以输入它,但输入是“Mobile Phone" 并且赛普拉斯在尝试寻找它时会抛出错误。表单中还有其他单个单词 id,我可以输入就可以了(谢天谢地,这不是 iframe),但我想知道是否有一种方法可以格式化调用以说明 space,当前代码如下:

export function typeMobilePhone() {
    cy.wait(4000)
    cy.frameLoaded('#podium-modal')
    cy
        .iframe('#podium-modal')
        .find('#Mobile Phone')
        .click()
        .type('123456789')

正如@Naren 所说,space 正在扼杀你的选择器。

您可以使用备用选择器(假设您无法更改 ID)

cy.iframe('#podium-modal')
  .find('[id="Mobile Phone"]')
  .type('123456789')