from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time
options = webdriver.ChromeOptions()
# options.add_argument("--headless") # Run headless if you wish
options.add_experimental_option('detach', True)
driver = webdriver.Chrome(options=options)
# for url in self.cruise_urls:
try:
driver.maximize_window()
driver.get(url) #load a cruise page
wait = WebDriverWait(driver, 10)
# Below try catch code is to handle the cookie consent pop-up. If you are not getting this pop-up, you can remove this code.
try:
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Accept']"))).click()
except Exception as e:
print("Accept button not found or not clickable:", e)
time.sleep(1)
a = (By.XPATH, "//*[@id='bookingCruiseDetails']/div[2]/div[2]/div[1]/h3")
cruise_title = wait.until(EC.visibility_of_all_elements_located(a))
#cruise_title = wait.until(EC.visibility_of_all_elements_located(By.XPATH, "//h2[@class='bcd-title__title']"))
print("cruise title > " + cruise_title.text)
except Exception as e:
print(e)
driver.close()