我想知道如何检查 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] 删除。
我来说两句