如何检查元素是否存在于 Cypress 的 DOM 中?

我想知道如何检查 Cypress 中网页的 DOM 中是否存在元素。

Selenium 中的这段代码在 Cypress 中的等价物是什么:

Boolean Display = driver.findElement(By.xpath("locator")).isDisplayed();
南克菲尔格

要使用 xpath 定位器进行查询,请安装cypress-xpath扩展。

使用 npm 安装
npm install -D cypress-xpath

用纱线安装
yarn add cypress-xpath --dev

在测试中

cy.xpath(locator)            // driver.findElement(By.xpath("locator"))

还要添加可见性检查,

cy.xpath(locator)            // driver.findElement(By.xpath("locator"))
  .should('be.visible')      // isDisplayed()

cy.xpath(locator)            // driver.findElement(By.xpath("locator"))
  .should('not.be.hidden')   // isDisplayed()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章