I have an element with a dynamic number. It's a unique order number that gets generated after every order. I am trying to fetch that number from a paragraph, <p>
tag using the getText() method, but webdriver returns a blank text after the test is run.
Executing :
boolean a = driver.findElement(By.xpath("(.//*[@id='alert-message']/div/p/strong)[1]")).isDisplayed();
returns false, suggesting the element is not displayed.
This is the HTML:
<div class="ng-scope" ng-include="templates[step]">
<div class="ng-scope" ng-controller="wReviewCtrl">
<div class="panel-alert ng-hide" ng-show="success<0">
<div class="panel-alert" ng-show="success>0 && hasRole('BUYER')">
<div class="alert-wrap in">
<div id="alert-message" class="alert alert-success" role="alert">
<div class="media">
<strong>Done!</strong>
<p>
A new order with Number
<strong class="ng-binding">JJ-MD000-12345</strong> //Order number
was generated. The order is now complete.
</p>
</div>
</div>
</div>
</div>
<div class="panel-alert ng-hide" ng-show="success>0 && hasRole('SELLER')">
<div class="alert-wrap in">
<div id="alert-message" class="alert alert-success" role="alert">
<div class="media">
<strong>Done!</strong>
<p>
I tried getting text using:
String orderNo = driver.findElement(By.xpath("(.//*[@id='alert-message']/div/p/strong)[1]")).getText();
System.out.println(orderNo);
I have tried all sorts of alternative combinations instead of .getText()
including:
.getAttribute("textContent");
.getAttribute("innerHTML");
.getAttribute("value"); //retuns NULL value
.getAttribute("outerText");
But none of them worked. How can I get that order number in the HTML?