Home > Enterprise >  Python : selenium find element angular
Python : selenium find element angular

Time:12-30

printscreen

I tried to read this line, but it doesn't work :

element = driver.find_element(By.XPATH,"//span[contains(@_ngcontent-whw-c159 data-cy,'hotel-title')]")
print(element.text)

Does anyone have an idea how to do this?

CodePudding user response:

hotel_names=[x.text for x in driver.find_elements(By.XPATH,"//h1[@class='title']")]

To get all the names on that page you can grab all h1 with class title.

wait=WebDriverWait(driver,10)                                 

driver.get("https://booking.luxairtours.lu/?lang=fr&adults=2&children=0&childages=0&sortBy=TotalPrice&sortOrder=desc&departuredate=2022-07-01&returndate=2022-07-17&themes=Custom6&durationstart=5&durationend=8")
hotel_names=[x.text for x in wait.until(EC.presence_of_all_elements_located((By.XPATH,"//h1[@class='title']")))]
print(hotel_names)

To make sure it loads use webdriver waits for the elements to appear.

Imports:

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

Outputs:

['LUXiClub Atlantica Aegean Blue Resort', 'LUXiClub Grecotel Marine Palace & Aqua Park', 'LUXiClub Insotel Punta Prima Resort & Spa', 'LUXiClub Sol Nessebar Palace', 'LUXiClub Grifid Club Hotel Bolero', 'LUXiClub Paloma Grida', 'LUXiClub Akassia Swiss Resort', 'LUXiClub Sol Nessebar Resort', 'LUXiClub Grand Hotel Holiday Resort', 'LUXiClub Relaxia Lanzasur Club']
  • Related