Home > database >  Extract element attribute using Selenium/Python in webpage
Extract element attribute using Selenium/Python in webpage

Time:12-29

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

enter image description here

CodePudding user response:

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