量角器 - 硒元素角度2打字稿

时间:2017-07-28 08:21:17

标签: html angular selenium protractor

从获得类名和id的div获取文本时遇到了一些麻烦,我试过了 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 textObjectHTML view, I need to get this link 0.0.0.0:3000...

HTML视图,我需要将此链接0.0.0.0:3000转换为字符串,你能帮助我吗?感谢:)

1 个答案:

答案 0 :(得分:1)

使用正则表达式提取URL:

element(by.css('#message-body'))
  .getText()
  .then(text => text.match(/[^"\s]+\/student\/register\/\?[^"\s]+/)[0])
  .then(url => console.log(url));