Using Xpath to get text from span- webdriver

10,614

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
Share:
10,614
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    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?