如何处理python硒Web驱动程序中的“下载密钥”按钮?

问题描述 投票:0回答:2

我不确定在“检查元素”下方应使用什么find_element_by_*来单击下载按钮。我是硒新手,仍在处理基础知识。

<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>
python selenium xpath css-selectors webdriverwait
2个回答
0
投票

您可以使用以下内容。

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

enter image description here


0
投票

对于文本为下载密钥文件的元素上的[click(),因为它是<a>节点,您必须为element_to_be_clickable()引入WebDriverWait,并且可以使用以下Locator Strategies

  • 使用LINK_TEXT

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Download Key File"))).click()
    
  • 使用PARTIAL_LINK_TEXT

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Download Key File"))).click()
    
  • 使用CSS_SELECTOR

    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
    
© www.soinside.com 2019 - 2024. All rights reserved.