0

I am trying to locate an xml element in selenium using xpath. It is nested in inside .

I have numbers 3498546 and 3498755 in hand. I need to match these numbers to the numbers listed in

  • elements and locate the specific .

    I have tried using various combinations with below: xpath=//*[@id="tabs"]/ul/li/[contains(div,'3498546')]

    But it never worked.

    Below is and example html code, I have around 100

  • listed in
    <div id="tabs">
        <ul>
            <li class="unknown">
            <span style="">DELIVERED</span>
            <a title="A1" onclick="submitForm('e1:eForm',1);return false;" 
                class="eLink" href="#">
            <div class="c1">"Year 2008
                                                              "
                <br>"3498546
                                                               "
                <br>
                </div>
                <strong>Date: </strong>05/14/2019
           </a>
        </li>
        <li class="unknown">
            <span style="">DELIVERED</span>
            <a title="A2" onclick="submitForm('e1:eForm',1);return false;" 
               class="eLink" href="#">
                <div class="c1">"Year 2008  
                                                             "
                    <br>"3498755
                                                          "
                    <br>
                </div>
                    <strong>Date: </strong>05/14/2019</a>
        </li>
      </ul>
    </div>
    

    I want to be able to locate and click the element which has the text 3498546 or 3498755.

  • lorenz
    • 178
    • 2
    • 10
    • `//*[text()[contains(.,'ABC')]]` from [this](https://stackoverflow.com/a/3655588/1430991) answer – gce Feb 11 '22 at 17:57

    3 Answers3

    0

    Here is the xpath based on the 3498546.

    //div[@class='c1'][contains(normalize-space(.),'3498546')]
    

    you can change the 3498546 value to the required number and use the same. In case you want to get all the elements having numbers and click each one of them then you can use the below xpath.

    //div[@id='tabs']//div[@class='c1']
    
    supputuri
    • 13,644
    • 2
    • 21
    • 39
    0
    //div[contains(text(),'3498755')]
    

    All you need is to look for the div element that its text contains the numbers you're looking for.

    Payam
    • 1,068
    • 12
    • 15
    • While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read [_How do I write a good answer_](https://stackoverflow.com/help/how-to-answer) to know more. - [From review](https://stackoverflow.com/review/low-quality-posts/23043693) – Roshana Pitigala May 17 '19 at 21:13
    0

    To click() on either of the elements with text as 3498546 or 3498755 you can use the following solutions:

    • 3498546:

      • Java & partialLinkText:

        driver.findElement(By.partialLinkText("3498546")).click();
        
    • 3498755:

      • Java & partialLinkText:

        driver.findElement(By.partialLinkText("3498755]")).click();
        
    undetected Selenium
    • 183,867
    • 41
    • 278
    • 352