2
  1. Get text which are in between tags DOM
<div id="div_ResultMessage" class="AlertmsgDiv">
    <div id="lblSuccessMessage" class="alert alert-success alert-dismissable">
        <div class="fa fa-check-square-o"></div>
            <button type="button" class="close" data-toggle="tooltip" title="Close" data-dismiss="alert" aria-hidden="true">×</button>
            Pur. Requisition No. Acc000056Zip created successfully
            <spam class="DivPrint">
                <a onclick="window.open('/ZipERP/CommonLayout/PrintPurchaseRequisition?id=769e9c10-7a5f-4205-920e-6f967f18811e')" href="#" class="fa fa-print" data-toggle="tooltip" title="Print">  
                </a>
            </spam>
        </div>
     </div>

I want to get this text if you can see it in DOM Pur. Requisition No. Acc000056Zip created successfully

I have tried fetching the text and store it in a var

var str = "";
 str = element(by.id('#lblSuccessMessage')).getAttribute('value');

and also this:

var str = "";
str = element(by.id('#lblSuccessMessage')).getText().then(function(text){
console.log(text);
return text;
});

Actually I am making a purchase requistion and there is alert which generates the Purchase requistition no but it contains Pr. no but surrounded with texts for that I am applying regEx and it says str.match() is not a function.

For regEx I have tried this

prno = str.match(/ Pur. Requisition No. Acc(\d+)/i)[0]; 
  • 1
    Can you elaborate more on your question? What are results of your trial? What is the concrete issue? To get a text or to parse it with regexp? – Alexey R. Dec 14 '18 at 9:37
  • @AlexeyR. i have attached the DOM and mentioned what i want – Rao Dec 14 '18 at 9:44
2

Okay I got solution for this:

var str = $('#lblSuccessMessage').getText().then(function(text){
        console.log(text); 
        var r = /\d+/;
        console.log((text.match(r)[0]));
        prno = text.match(r)[0];
        //prno = str.match(/ Pur. Requisition No. Acc(\d+)/i)[0];
      });
      //console.log("Purchase requistion no..."+prno);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.