如何处理点击&x201C;下载密钥”;python中selenium web驱动程序中的按钮?

如何处理点击&x201C;下载密钥”;python中selenium web驱动程序中的按钮?,python,selenium,xpath,css-selectors,webdriverwait,Python,Selenium,Xpath,Css Selectors,Webdriverwait,我不确定我应该使用什么查找元素\u by.*来点击下载按钮。我对selenium还不熟悉,仍然在处理基础知识 <a href="#" style="font-size:15px;" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.forms['activationpage3'],'activationpage3:j_id_id21,activationpage3:j_id_id21','');}return false"

我不确定我应该使用什么
查找元素\u by.*
来点击下载按钮。我对selenium还不熟悉,仍然在处理基础知识

<a href="#" style="font-size:15px;" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.forms['activationpage3'],'activationpage3:j_id_id21,activationpage3:j_id_id21','');}return false">Download Key File</a>

您可以使用以下选项

driver.find_element_by_xpath("//a[.='Download Key File']").click()

您可以使用以下选项

driver.find_element_by_xpath("//a[.='Download Key File']").click()

请在文本为的元素上单击()

  • 使用
    链接文本

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Download Key File"))).click()
    
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Download Key File"))).click()
    
  • 使用部分链接文本

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Download Key File"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Download Key File"))).click()
  • 使用
    CSS\u选择器

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[onclick*='activationpage3']"))).click()
    
  • 使用
    XPATH

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@onclick,'activationpage3') and contains(., 'Download Key File')]"))).click()
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • 在元素上单击()
    ,文本为下载密钥文件,因为它是

    • 使用
      链接文本

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Download Key File"))).click()
      
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Download Key File"))).click()
      
    • 使用部分链接文本

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Download Key File"))).click()
    
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Download Key File"))).click()
    
  • 使用
    CSS\u选择器

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[onclick*='activationpage3']"))).click()
    
  • 使用
    XPATH

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@onclick,'activationpage3') and contains(., 'Download Key File')]"))).click()
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

  • 我建议您阅读一些指南/教程和文档。这种问题最终对提问者和未来的读者都没有什么价值。我建议阅读一些指南/教程和文档。这种问题最终对提问者和未来的读者都没有什么价值。