1

ive got some troubles with getting text from div which has got class name and id, I tried element(by.css('.panel-body')).getText();<-return object Objct element(by.className('panel-body')).getText();<-return object Object element(by.id('message-body')).getText();<-return object Object element(by.xpath('//*[@id="message-body"]/text()[3]')).getText()<-return textObject there is HTML view, I need to get this link 0.0.0.0:3000...

HTML view, I need to get this link 0.0.0.0:3000 into string, Can you help me? Thanks:)

Jędrek Markowski
  • 444
  • 3
  • 6
  • 25

1 Answers1

1

Use a regular expression to extract the URL:

element(by.css('#message-body'))
  .getText()
  .then(text => text.match(/[^"\s]+\/student\/register\/\?[^"\s]+/)[0])
  .then(url => console.log(url));
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • Thanks, do you know maybe how to return this url out of that function? Its undefined when I return it inside .then, and when I return all element with return inside .then it returns object of element :) – Jędrek Markowski Jul 28 '17 at 11:35
  • 1
    You are dealing with asynchronous calls, thus it's not possible to directly get the result from a function. That said, the function returns a `Promise` that can be resolved with `.then`. So if you wish to use the `url` elsewhere, then store it in a global variable or return the `Promise` and resolve it when you need the value. – Florent B. Jul 28 '17 at 11:45