是否可以通过nightwatch.js设置元素的Style属性的值?如果是,那么如何

Is it possible to set the value of Style property of an element by nightwatch.js ? if yes then how?

本文关键字:如果 属性 js nightwatch 可以通过 设置 元素 是否 Style      更新时间:2023-09-26

我正在使用nightwatch.js,我对这个自动化测试很陌生,我想通过nightwatch.js将值设置到元素的style属性中,所以我想问,这可能吗?如果这是可能的,那么我们如何实现它。

我可以访问样式属性值,并可以按照nightwatchapi命令进行检查,但我找不到任何方法使用nightwatch.js 将样式值设置为元素

browser.expect.element('#main').to.have.css('display').which.equals('block');

您可以使用Nightwatch Selenium执行协议来更改元素的样式属性。使用Selenium执行协议,您可以在要测试的站点上执行任意javascript。

例如,你可以这样使用它:

browser
.execute("document.getElementById('main').style.display = 'block';")
.expect.element('#main').to.have.css('display').which.equals('block');