Home > Back-end >  Extract value from read only form selenium python
Extract value from read only form selenium python

Time:10-18

This was the html element

<div ><!----><input _ngcontent-acc-c94="" matinput="" readonly="true"  style="display: none;" id="mat-input-0" aria-invalid="false" aria-required="false"><!----><!----><span _ngcontent-acc-c94="" ><span _ngcontent-acc-c94="" ><a _ngcontent-acc-c94="" target="_blank" rel="noopener" href="mailto:[email protected]">[email protected]</a></span><!----><!----></span><!----><span ><label  id="mat-form-field-label-1" for="mat-input-0" aria-owns="mat-input-0"><!----><mat-label _ngcontent-acc-c94="" >E-mail</mat-label><!----><!----></label><!----></span></div>

My code:

owner_id=driver.find_element(By.XPATH,'')
owner_id=driver.find_element(By.CSS_SELECTOR,'')

I have tried extracting using xpath,css selector,classsname and nothing worked. Please help me out incase you guys know

CodePudding user response:

Use WebDriverWait() and wait for element to be visible and following xpath.

owner_id=WebDriverWait(driver,20).until(EC.visibility_of_element_located((By.XPATH,"//span[contains(., 'E-mail')]/preceding-sibling::span[1]//a")))
print(owner_id.text)
print(owner_id.get_attribute("textContent"))

Import below libarries

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

CodePudding user response:

I tried with the Html source you posted, I can get the email id using the below code:

print(driver.find_element(By.CSS_SELECTOR, ".mat-form-field-infix.ng-tns-c64-9 span a").text)

Output:

[email protected]
  • Related