尝试查找以数字开头的 id 时 cypress 出错

Error in cypress when trying to find an id that starts with a number

我正在尝试使用 cypress 通过 id 查找元素,但是当我使用 cypress selector playground 时,它给出了以下代码

get("# -2")

但是当我在 cypress 中 运行 这个时,我得到一个错误

Syntax error, unrecognized expression: # -2

我什至尝试手动添加 ID,例如:

get("#33-2")

还是不行。使用 类 一切正常!但不是身份证。 这是我尝试定位的元素的示例

<div id="1-20">Hello world</div>

我在本地试过了,#1-20 工作正常。

cy.get("#1-20").should('have.text', 'Hello world')

试试这个:

cy.get("#1-20").should('exist')

Cypress 实际上返回了一个奇怪的字符串,它本身给出了一个错误,但是手动写入 ID 代码有效。

https://prnt.sc/1gqnbul