是否可以通过nightwatch.js设置元素的Style属性值?如果是的话怎么样? [英] Is it possible to set the value of Style property of an element by nightwatch.js ? if yes then how?

查看:96
本文介绍了是否可以通过nightwatch.js设置元素的Style属性值?如果是的话怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working with nightwatch.js and i am quite new into this automation testing, i want to set the value into the style property of an element by nightwatch.js, so i am asking, is it possible ? if it is possible then how can we implement it.

我可以访问样式属性值并可以通过以下nightwatch api命令检查但我找不到任何方法使用nightwatch.js将样式的值设置为元素

I can access the style property values and can check by following nightwatch api command but i couldn't find any way to set the style's value to an element using nightwatch.js

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


推荐答案

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

You can use the Nightwatch Selenium execute protocol to change the style property of an element. With the Selenium execute protocol you can execute arbitrary javascript on the site to be tested.

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

For example you can use it like this:

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

这篇关于是否可以通过nightwatch.js设置元素的Style属性值?如果是的话怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆