0

I'm trying find a list of data on a webpage, but the list is hidden and therefore I need to navigate the page. Whatever I try, I am unable to find a hyperlink tag to then click on it.

Does anyone know how to navigate to the following hyperlink and click:

    <li>
    <a href="#" class="accordion-toggle">
    == $0
        <span class="fa fa-briefcase">::before</span>
        <span class="sidebar-title">Batches</span>
        <span class="caret">::after</span>
        ::after
    </a>
    <ul class="nav sub-nav">::before
        <li class="active">
            <a href="#" aria-expanded="true">
                <span class="fa fa-table"></span>
                "Lijst"
                ::after
            </a>
        </li>
        ::after
    </ul>
</li>

I cannot refer to the page because you need login, but there are four hyperlinks with the same href="#" and class="accordion-toggle". Therefore I'm interested in finding out how to select and click this.

Dervissss
  • 73
  • 6

1 Answers1

0

Turns out xpath is the solution, when done right. the answer to the question when using an absolute path:

hyperlink_element = driver.find_element_by_xpath("/html/body/span[1]/div[2]/div[1]/aside[1]/div[1]/ul[1]/li[5]/a[1]")

The answer using a relative path also works when referring to the class:

hyperlink_element = driver.find_element_by_xpath("//ul[@class='nav sidebar-menu']/li[5]/a[1]")

Since find_element_by_* are deprecated in the latest version of selenium, the propper way to click on the hyperlink would be:

hyperlink_element = driver.find_element(By.XPATH, "/html/body/span[1]/div[2]/div[1]/aside[1]/div[1]/ul[1]/li[5]/a[1]")
hyperlink_element.click()
Dervissss
  • 73
  • 6