Reputation: 3728
Html:
<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 5
but i'm getting empty value in the pubCount
String, Please suggest if any mistake in my xpath
Upvotes: 1
Views: 231
Reputation: 3357
The XPath expression in itself is correct, it selects your node as expected. A simple test with xmllint
gives:
> xmllint --xpath "//strong[@ng-bind='summary.PublishedIssuedRecent']" ~/test.html
<strong class="text-xl ng-binding" ng-bind="summary.PublishedIssuedRecent">5</strong>
So the error is outside your XPath expression.
By the way, if you just need the text of the node, you can use
> xmllint --xpath "//strong[@ng-bind='summary.PublishedIssuedRecent']/text()" ~/test.html
5
Upvotes: 1
Reputation: 22605
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();
Upvotes: 1