Selenium Python how to read characteristics from a DIV?

Question:

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

Asked By: Percy Herrera

||

Answers:

First identify the element and then get_attribute()

driver.find_element(By.XPATH, '//div[data-qa="posting house"]').get_attribute("data-to-posting")
Answered By: KunduK

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
Answered By: khaled koubaa
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.