How to click on a element through Selenium Python

The element with text as Export is a dynamically generated element so to locate the element you have to induce WebDriverWait for the element to be clickable and you can use either of the Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.layerConfirm>div[data-hover="tooltip"][data-tooltip-display='overflow']"))).click()
    
  • Using XPATH:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'layerConfirm')]/div[@data-hover="tooltip" and text()='Export']"))).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
    

Leave a Comment