Reputation: 4324
Below I have four radio buttons that each select a passenger.
<input checked="checked" name="passenger" id="passenger-0" data-passengerindex="0" type="radio">
<input checked="checked" name="passenger" id="passenger-1" data-passengerindex="1" type="radio">
<input checked="checked" name="passenger" id="passenger-2" data-passengerindex="2" type="radio">
<input checked="checked" name="passenger" id="passenger-3" data-passengerindex="3" type="radio">
Below is a block of code that shows a row of seats (in row 6), some infants seats (class="seat infant")
and the others normal seats (normal seats are seats noinfant - class="seat noinfant"
and seats class="seat"
.
<td>
<a href="#6A" title="Seat Suitable for Infants 6A" data-seat="6A" data-seatid="81374518" data-seatgroup="0" class="seat infant" data-personid="" data-infantseat="True">
<span>Seat Suitable for Infants 6A</span>
</a>
</td><td>
<a href="#6B" title="Seat Suitable for Infants 6B" data-seat="6B" data-seatid="81374519" data-seatgroup="0" class="seat infant" data-personid="" data-infantseat="True">
<span>Seat Suitable for Infants 6B</span>
</a>
</td>
<td>
<a href="#6C" title="Seat Suitable for Infants 6C" data-seat="6C" data-seatid="81374520" data-seatgroup="0" class="seat infant" data-personid="" data-infantseat="True">
<span>Seat Suitable for Infants 6C</span>
</a>
</td>
<td class="aisle">6</td>
<td>
<a href="#6D" title="Seat Suitable for Infants 6D" data-seat="6D" data-seatid="81374522" data-seatgroup="1" class="seat noinfant" data-personid="" data-infantseat="True">
<span>Seat Suitable for Infants 6D</span>
</a>
</td>
<td>
<a href="#6E" title="Seat Suitable for Infants 6E" data-seat="6E" data-seatid="81374523" data-seatgroup="1" class="seat" data-personid="" data-infantseat="True">
<span>Seat Suitable for Infants 6E</span>
</a>
</td>
<td>
<a href="#6F" title="Seat Suitable for Infants 6F" data-seat="6F" data-seatid="81374524" data-seatgroup="1" class="seat infant" data-personid="" data-infantseat="True">
<span>Seat Suitable for Infants 6F</span>
</a>
</td>
</tr>
When a seat is selected, the below happens:
class="seat infant"
to class="seat infant reserved selected
for infant seatsclass="seat noinfant"
to class="seat noinfant reserved selected
OR class="seat"
to class="seat reserved selected
Below is what I need help implementing:
Starting from Row 1 and continuing along
We don't need to actually select a passenger as they get selected automatically after selecting a seat, and first passenger is already selected when page is loaded.
Does anybody as I have only used Python for 4 days so no way near advanced know how to implement the above?
Upvotes: 1
Views: 107
Reputation: 473873
The idea would be:
data-hasinfant
attribute), decide which seat to picknot()
to get to the non-selected and non-reserved seatsSample implementation:
for passenger in driver.find_elements_by_css_selector("ol.passengerlist li[data-personid]"):
passenger.click()
has_infant = passenger.get_attribute("data-hasinfant")
# choose seats
if has_infant:
# select a non-selected infant seat
seat = driver.find_element_by_css_selector(".planebody a.seat.infant:not(.reserved):not(.selected)")
else:
# select a non-reserved non-selected seat
seat = driver.find_element_by_css_selector(".planebody a.seat:not(.reserved):not(.selected)")
print("Passenger: %s, choosing seat: %s" % (passenger.text.strip(), seat.get_attribute("data-seat")))
seat.click()
Upvotes: 1