0

i have the following div:

<div 
data-qa="posting house" data-id="25364875" data-to-posting="25364875_pos" 
class="sc-Xml_house"> ... 
<div>

How can I read the value of the label: "data-to-posting"

thanks

  • Use get_attibute() method of the webelement: https://stackoverflow.com/questions/30324760/how-to-get-attribute-of-element-from-selenium – pcalkins Sep 26 '22 at 20:23
  • @BarrythePlatipus this is link https://urbania.pe/buscar/venta-de-departamentos-en-villa-maria-del-triunfo--lima--lima?currencyId=6 thanks for your help – Percy Herrera Sep 26 '22 at 21:44

2 Answers2

1

try WebDriverWait and visibility_of_element_located:

from selenium.webdriver.common.by import By #make sure to add this import 

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

elem = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR,'.sc-Xml_house'))).get_attribute("data-to-posting")

# visibility_of_element_located --> waiting until an element is present on the DOM of a page and visible
khaled koubaa
  • 836
  • 3
  • 14
0

First identify the element and then get_attribute()

driver.find_element(By.XPATH, '//div[data-qa="posting house"]').get_attribute("data-to-posting")
KunduK
  • 32,888
  • 5
  • 17
  • 41