I need to choose (open) every movie in the list, starting by first one to last, once in one, go back and open the next movie in the list until last movie. But i got a problem because the code selects the last movie and opens it not the first.
I don't know how to select the first one and repeat the process to every movie in the list.
This is the code:
from selenium import webdriver
import time
URL = 'https://www.cineplanet.cl/peliculas'
XPATH_VER_MAS_PELICULAS = '//button'
ClASS_CARTELERA = 'movie-info-details'
XPATH_COMPRAR = '//div[@class="movie-info-details"]/div[@class="movie-info-details--wrapper"]/div[@class="movie-info-details--first-button-wrapper"]/button'
PATH = 'C:\\Program Files\\chrome-driver\\chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.get(URL)
def available_movies():
try:
select = driver.find_element_by_class_name(ClASS_CARTELERA)
allOptions = select.find_elements_by_xpath(XPATH_COMPRAR)
for option in allOptions:
option.click()
except:
pass
print (driver.title)
time.sleep(5)
while True:
try:
if XPATH_VER_MAS_PELICULAS:
driver.find_elements_by_xpath(XPATH_VER_MAS_PELICULAS)[-1].click()
time.sleep(5)
else:
break
except:
break
available_movies()
time.sleep(2)
driver.quit()
CLASS_CARTELERAWebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, ClASS_CARTELERA)))