简体   繁体   中英

How to handle click on “Download key” button in selenium web driver in python?

I am not sure what find_element_by_* I should use with respect to below "inspect element" to click on the download button. I am new to selenium still dealing with basics.

<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>

You can use the below.

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

在此处输入图片说明

To click() on the element with text as Download Key File as it is an <a> node you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies :

  • Using LINK_TEXT :

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

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

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

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@onclick,'activationpage3') and contains(., 'Download Key File')]"))).click()
  • Note : You have to add the following imports :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM