Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
Nightwatch JS | Getting Next Sibling Text

I am attempting to write a function that can acquire the text value of a nextSibling node underneath a label bracket. I need to be able to put that text into a global variable that I can reference later in the test, but my current function, while it is retrieving the webElementId, is not retrieving the text. Instead, my console.log function is outputting a blank value.

To give some context on the code in question, here is the HTML layout of the field I am attempting to parse.

<iframe> id=[some_id]
  #document
    <html>
      <head>
        <body>
          <div> id=[some_id]
            <form> id=[some_id]
              <div> id=[some_id]
                <div> id=[some_id]
                  <div> style=[some_style]
                    <label>[some text]<label>
                      [text field in question]

That's just the basic layout, but here is the code snippet that I am attempting to use to grab the sibling node, get the id, and then get the text of the webElementId.

.getNextSibling('div[id=popover_content] > form[id=perform_sub_task_form] > div[id=perform_task] > div[id=dialog_container] > div > label:nth-of-type(8)', function(dateObj) {
  let dateVal = dateObj.value.getId()
    console.log(`datevalue: ${dateVal}`)
    browser.elementIdText(`${dateVal}`, function(result) {
      console.log('\n' + result.value)
      initial_date = result.value
})
 })

I have already attempted to simplify this and run a callback function on just the .getNextSibling function using result.value.getText(), that just results in Nightwatch telling me that the function doesn't exist. Reading the documentation for the getNextSibling() function, I found that getId() can be added onto the callback, so I decided to use that to my advantage and attempt to use the provided webElementId and write the snippet above.

I know that my code works up to the first console.lg function, because the webElementId is successfully rendered in the terminal I'm running off of. But once it tries to log the result.value, a blank line appears in the terminal.

My question is, how can I edit this snippet above so that it stops giving me a blank value? Is there an issue with my browser.elementIdText() function?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!