Python Selenium:通过href查找元素

Python Selenium:通过href查找元素,python,selenium-webdriver,Python,Selenium Webdriver,如何在selenium(使用python)中找到以下html的元素: <a href="/user/login" onclick="ttweb.UserOperations.Login.OpenLoginPopup({ LoginUrl: '/user/login', RedirectUrl: '/' }); return false;">Login</a> 根据您共享的HTML,通过href查找元素,您可以使用以下任一选项: css\u选择器: driver.fi

如何在selenium(使用python)中找到以下html的元素:

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


根据您共享的HTML,通过
href
查找元素,您可以使用以下任一选项:

  • css\u选择器

    driver.find_element_by_css_selector("a[href=/user/login]")
    
    driver.find_element_by_xpath("//a[@href='/user/login']")
    
  • xpath

    driver.find_element_by_css_selector("a[href=/user/login]")
    
    driver.find_element_by_xpath("//a[@href='/user/login']")
    
  • xpath
    (多属性):


  • 欢迎来到StackOverflow!到目前为止你试过什么吗?StackOverflow不是一个免费的代码编写服务,它希望您能够这样做。请更新您的问题,以显示您已经尝试过的内容,并显示您在某个应用程序中面临的特定问题。欲了解更多信息,请参阅,然后点击。从selenium.webdriver.common.by导入by driver.find_元素(by.XPATH,//button[text()=“Some text”]')驱动程序。find_元素(by.XPATH,//button')