I need to add a delay there, but any type of delay makes the code to crash. I need that because this script clicks so fast that the web can not process both and only registers the second one.
""" Returns a pair of web elements corresponding to the first of the morning
and afternoon bunch of slots*'"""
available_slot_pairs = []
""" The list of available to book slots """
available_rows = []
rows = self.driver.find_elements_by_class_name("fc-event-container")
for row_index in range(row_offset, len(rows)):
""" Range is determined by row_offset & number of rows(18)"""
row = (rows[row_index])
self.boxcheck(By.CLASS_NAME, "fc-timeline-event")
slots = row.find_elements_by_class_name("fc-timeline-event")
slot = slots[0]
slot6 = slots[6]
if 's-lc-eq-avail' in slot.get_attribute("class") and 's-lc-eq-avail' in slot6.get_attribute("class"):
available_slot_pairs.append((slot, slot6))
available_rows.append(row_index)
return available_slot_pairs, available_rows
def select_seats(self,seat_num):
""" Clicks the desired available seats and looks for the "SUBMIT TIMES" button to register the selected seats*'"""
available_slot_pairs, available_rows = self.find_first_available_slots_elements(row_offset=0)
seats_selected = 0
for morning_slots_first, afternoon_slots_first in available_slot_pairs:
morning_slots_first.click()
#I NEED TO ADD DELAY HERE, BUT NOTHING SEEMS TO WORK <-----------------------------------
afternoon_slots_first.click()
seats_selected+=1
if seats_selected >= seat_num:
self.fasten(By.ID, 'submit_times')
self.driver.find_element_by_id('submit_times').click()
return
I can not find any solution to this. I know that after the first click(), if i add this: self.fasten(By.ID, 'submit_times'), the script will wait just enough for the web to process the clicks, any ideas?
Error:
Message: stale element reference: element is not attached to the page document
This error doesn't appear if no delay is added