Selenium: finding element by href

How would you find an element in selenium (with python) of the following html:

<a href="/user/login" onclick="ttweb.UserOperations.Login.OpenLoginPopup({ LoginUrl: '/user/login', RedirectUrl: '/' }); return false;">Login</a>


1 answer

  • answered 2017-11-15 05:15 DebanjanB

    As per the HTML you have shared to find the element by href you can use either of the following:

    1. css_selector:

    2. xpath:

    3. xpath (Multiple Attributes):

      driver.find_element_by_xpath("//a[@href='/user/login' and text()='Login']")