Is it possible to set the value of Style property

2020-04-18 06:25发布

问题:

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.

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');

回答1:

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');