Milos Jovanovic
Milos Jovanovic

Reputation: 31

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>

Code

Upvotes: 0

Views: 11248

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193338

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

  1. css_selector:

    driver.find_element_by_css_selector("a[href=/user/login]")
    
  2. xpath:

    driver.find_element_by_xpath("//a[@href='/user/login']")
    
  3. xpath (Multiple Attributes):

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

Upvotes: 2

Related Questions