Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nightwatch - Node.js - How to remove/delete HTML elements?

Apparently, in Nightwatch, there's no 'document' or 'window' object. There is a 'browser' object which seems to be similar.

Tried using .getElementById(), .remove(), .removeChild() and Nightwatch doesn't recognize the methods.

like image 313
Vladislav Bulanov Avatar asked May 30 '26 06:05

Vladislav Bulanov


1 Answers

You have to use .execute() function to write document statements. In the below example I am using the querySelector to find the element and then asserting its innertext in the callback.

'Nightwatch JS Example': function(browser) {
    browser.url('https://example.com').waitForElementVisible('body').execute(function() {
        return document.querySelector(selector).innerText 
    }, [], function(result) {
        this.assert.equal(result.value, 'Some text')
    })
}
like image 84
Alapan Das Avatar answered Jun 02 '26 01:06

Alapan Das