Search code examples
htmlseleniumxpathwebdriverwait

Extract element attribute using Selenium/Python in webpage


Pink stuff is the email I have to derive from the webpage black/blue stuff is confidential using py3.6 and s


Solution

  • The pink stuff refers to the href and title attributes.

    To extract the href:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[@automation-id='cpd-email-href']"))).get_attribute("href"))
    

    To extract the title:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[@automation-id='cpd-email-href']"))).get_attribute("title"))
    

    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