Search code examples
javascripthtmlcssnightwatch.js

How can I read the inner div text for an element in nightwatch.js


I am trying to read the value of a cell in a table, the css looks like this:

<div data-testid="cellvalue_row-1_col-0" class="Table-cellContent" xpath="1"><span data-testid="tableCellContent_text">Dummy</span></div>

How can I read the value "DUMMY" using nightwatch.js pages commands?


Solution

  • I would suggest to go through the official docs available at https://nightwatchjs.org/api/getText.html#apimethod-page.

    You should be using getText api of nightwatchjs to read the text.

    The selector can be as below.

    browser.getText('.Table-cellContent span', (result) => {
     console.log(result.value)
    })