i have the following div:
<div
data-qa="posting house" data-id="25364875" data-to-posting="25364875_pos"
> ...
<div>
How can I read the value of the label: "data-to-posting"
thanks
CodePudding user response:
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
CodePudding user response:
First identify the element and then get_attribute()
driver.find_element(By.XPATH, '//div[data-qa="posting house"]').get_attribute("data-to-posting")