Prabu Prabu - 7 months ago 59
Java Question

GetText() clarification - xpath not returning the value


<strong class="text-xl ng-binding" ng-bind="summary.PublishedIssuedRecent">5</strong>

my xpath:

@FindBy(how = How.XPATH, using = "//strong[@ng-bind='summary.PublishedIssuedRecent']")
public WebElement countRecentlyPublishedApplication;

String pubCount = countRecentlyPublishedApplication.getText();

my Expectation

i want to extract the value of

but i'm getting empty value in the
String, Please suggest if any mistake in my xpath


From attribute ng-bind I'm guessing you're trying to scrap angularJS application and you're using selenium web driver.

Problem with angular is, it is rendered by javascript after the page loads. So on beginning element you want to scrap might not be there. Solution might be to wait a second until angulars finishes rendering and then try to find element.

driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
WebElement pubCount = driver.findElement(By.xpath( "//strong[@ng-bind='summary.PublishedIssuedRecent']")).getText();