Lw2_0702230135 Lw2_0702230135 Lw2_0702230135

How to write xpath for li content for breadcrumb items

60 views Asked by At

I want to write an xpath for verify the Custom Report text without index.

HTML:

<ol>
    <li>
        <a href="https://dumpy.url.com">Lw2_0702230135</a>
    </li>
    <li>
        <a href="https://dumpy.url.com">Report</a>
    </li>
    <li>
        Custom Report
    </li>
</ol>
2

There are 2 answers

0
risahbhc32 On BEST ANSWER

You can use the following xpath:

//ol/li[contains(text(), "Custom Report")]
0
undetected Selenium On

Given the HTML:

<ol>
    <li>
        <a href="https://dumpy.url.com">Lw2_0702230135</a>
    </li>
    <li>
        <a href="https://dumpy.url.com">Report</a>
    </li>
    <li>
        Custom Report
    </li>
</ol>

To identify the element with text Custom Report you can use the following xpath based locator strategy:

//ol/li[last()]

Code (Python):

element = driver.find_element(By.XPATH, "//ol/li[last()]")