Check the simplified working code below with explanation in comments.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Chrome()
driver.get("https://www.nepremicnine.net/oglasi-prodaja/gorenjska/kranj/kranj/stanovanje/letnik-od-1980-do-1989/")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
# accept cookies
wait.until(EC.element_to_be_clickable((By.ID, "CybotCookiebotDialogBodyButtonAccept"))).click()
# wait for the ads to load and then store it into a variable
all_Ads = wait.until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@class='property-details']")))
# Loop through each ad and print it's text
for ad in all_Ads:
print(ad.text)
print(ad.get_attribute("data-href"))
print("---------------------")
Result:
Prodaja: Stanovanje, 1-sobno
KRANJ
47 m2, 1-sobno, zgrajeno l. 1986, adaptirano l. 2021, 7. nad., prodamo. Cena: 229.000,00 EUR
47,00 m2 1986 7
229.000,00 €
Fesst nepremičnine d.o.o.
https://www.nepremicnine.net/oglasi-prodaja/kranj-stanovanje_6980815/
---------------------
Prodaja: Stanovanje, 1,5-sobno
NOVO
KRANJ
47,4 m2, 1,5-sobno, zgrajeno l. 1989, 1/5 nad., prodamo. Cena: 198.000,00 EUR
47,40 m2 1989 1/5
198.000,00 €
BAZA agencija d.o.o.
https://www.nepremicnine.net/oglasi-prodaja/kranj-stanovanje_6993792/
---------------------
Prodaja: Stanovanje, 2-sobno
KRANJ
72,3 m2, 2-sobno, zgrajeno l. 1982, adaptirano l. 2009, 4/7 nad., prodamo. Cena: 252.000,00 EUR
72,30 m2 1982 4/7
252.000,00 €
Nepremičnina posredovanje d.o.o.
https://www.nepremicnine.net/oglasi-prodaja/kranj-stanovanje_6849482/
---------------------
Prodaja: Stanovanje, 3-sobno
KRANJ
73,9 m2, 3-sobno, zgrajeno l. 1989, 4/4 nad., prodamo. Cena: 230.000,00 EUR
73,90 m2 1989 4/4
230.000,00 €
Fesst nepremičnine d.o.o.
https://www.nepremicnine.net/oglasi-prodaja/kranj-stanovanje_6895075/
---------------------
Prodaja: Stanovanje, 3-sobno
KRANJ
77 m2, 3-sobno, zgrajeno l. 1989, 1/5 nad., prodamo. Cena: 259.000,00 EUR
77,00 m2 1989 1/5
259.000,00 €
BAZA agencija d.o.o.
https://www.nepremicnine.net/oglasi-prodaja/kranj-stanovanje_6965426/
---------------------
Prodaja: Stanovanje, 3,5-sobno
KRANJ
77 m2, 3,5-sobno, zgrajeno l. 1989, adaptirano l. 2023, 1/5 nad., prodamo. Cena: 259.000,00 EUR
77,00 m2 1989 1/5
259.000,00 €
Zasebna ponudba
https://www.nepremicnine.net/oglasi-prodaja/kranj-stanovanje_6836639/
---------------------
Prodaja: Stanovanje, 3-sobno
KRANJ
106 m2, 3-sobno, zgrajeno l. 1983, adaptirano l. 2013, 2. nad., prodamo. Cena: 322.000,00 EUR
106,00 m2 1983 2
322.000,00 €
Fesst nepremičnine d.o.o.
https://www.nepremicnine.net/oglasi-prodaja/kranj-stanovanje_6988403/
---------------------
Prodaja: Stanovanje, 3-sobno
KRANJ
118 m2, 3-sobno, zgrajeno l. 1980, adaptirano l. 2018, 2/2 nad., prodamo. Cena: 310.000,00 EUR
118,00 m2 1980 2/2
310.000,00 €
Aeon nepremičnine, d.o.o., PE Izola
https://www.nepremicnine.net/oglasi-prodaja/kranj-stanovanje_6817465/
---------------------
Prodaja: Stanovanje, 3-sobno
KRANJ, PLANINA
63 m2, 3-sobno, zgrajeno l. 1987, adaptirano l. 2022, P/4 nad., klet 8 m2, stanovanje predelano v 3-sobno. Nahaja se v p...
63,00 m2 1987 P/4
249.000,00 €
Zasebna ponudba
https://www.nepremicnine.net/oglasi-prodaja/kranj-planina-stanovanje_6987918/
---------------------
Prodaja: Stanovanje, 3-sobno
KRANJ, PLANINA
106 m2, 3-sobno, zgrajeno l. 1983, adaptirano l. 2013, 2/3 nad., prodamo. Cena: 322.000,00 EUR
106,00 m2 1983 2/3
322.000,00 €
Zasebna ponudba
https://www.nepremicnine.net/oglasi-prodaja/kranj-planina-stanovanje_6989373/
---------------------
Prodaja: Stanovanje, 1,5-sobno
KRANJ, PLANINA 1
53 m2, 1,5-sobno, zgrajeno l. 1980, adaptirano l. 2015, 2/4 nad., Prodam stanovanje Planina 1, prodamo. Cena: cca 220.00...
53,00 m2 1980 2/4
220.000,00 €
Zasebna ponudba
https://www.nepremicnine.net/oglasi-prodaja/kranj-planina-1-stanovanje_6985299/
---------------------
Process finished with exit code 0
UPDATE: Answer to second question asked in the comments.
# Extracting meta content for position
metaContent = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//div[@class='col-md-6 col-md-12 position-relative']//meta[@itemprop='position']")))
for content in metaContent:
print(content.get_attribute("content"))
Result:
1
2
3
4
5
6
7
8
9
10
11
Process finished with exit code 0
find_element(withouts) insidefor-loop - it may need.for relative xpath".//div[@class='propertydetails']". Without.it can always give the same (first) element.