user2812503
user2812503

Reputation: 21

Using Xpath to get text from span- webdriver

I'm using selenium webdriver to get some text on my webpage using xpath.

This is the code

<a class="ng-binding" data-toggle="tab" href="#tabCreatedByMe">
                            Created By Me                              
<span class="badge ng-binding">3</span>
</a>

I need to get the number '3'. this number is changing everytime

I made this code but it does not return anything

public String getAmountSubtab1() throws InterruptedException{
    WebElement s =  driver.findElement(By.xpath("//*[@class='badge ng-binding']"));
    return s.getText(); }

Suggestions?

Upvotes: 2

Views: 10751

Answers (1)

Vinay
Vinay

Reputation: 754

Are you sure you have only one span with the class badge ng-binding It might be that you might have another span before this with the same class name. Advised not to use class name when identifying an element. Use this xpath. Should work.

//a[contains(text(), 'Created By Me')]/span

Upvotes: 1

Related Questions