我对cypress很陌生,我想用xpath作为元素定位器。
如何使用xpath声明对象?我现在有这样的设计。如何为我的用户名和submitBtn元素使用xpath?
export default class LoginPage extends BasePage {
constructor() {
super()
}
username = "#username";
submitBtn = "#_submit";
fillLoginUser(myUser) {
let field = cy.get(this.username);
field.clear();
field.type(Cypress.env(myUser));
this.submit(this.submitBtn)
}
}发布于 2021-02-09 05:32:14
您可以为xpath使用插件
安装与npm
npm install -D cypress-xpath包含在项目的柏树/支持/index.js中
require('cypress-xpath')您可以使用cy.xpath而不是cy.get。
cy.xpath('//ul[@class="todo-list"]//li')https://stackoverflow.com/questions/66111426
复制相似问题