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:)

2
  • Ok, getText returns promise, is there any way to extract string from that object? Commented Jul 28, 2017 at 9:56
  • 1
    you have to resolve the promise. pls refer this link - stackoverflow.com/questions/29478905/… Commented Jul 28, 2017 at 10:02

1 Answer 1

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));
Sign up to request clarification or add additional context in comments.

2 Comments

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 :)
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.