1

I'm having an issue where an error appears in my PYTHON GUI stating 'ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with', so it's stopping my script.

Virtually I have an image below where I select the seats of the passengers in their outbound flight by selecting a seat, the next radio button is selected and then another seat is selected and it continues.

However, after selecting the seat for the last passenger on the outbound flight, it will automatically go down the inbound list and select the first passenger's radio button in there, but the script stops with the error.

I tried stating using xpath to wait for the plane map for the inbound map to appear before clicking on the inbound passengers but it doesn't like that.

My question is that how can I get the script to select the seats for the inbound flight, exactly like the outbound flight once it does the switch from outbound to inbound?

Below is the code I have for selecting passengers and their seats:

#seats selection - outbound

for outbound_passenger in driver.find_elements_by_css_selector("ol[data-flightbound='Outbound'] li[data-personid]"):
    outbound_passenger.click()

#driver.find_elements_by_css_selector("ol.passengerlist li[data-personid]"):

    outbound_has_infant = outbound_passenger.get_attribute("data-hasinfant")

# choose seats
    if outbound_has_infant:
        # select a non-selected infant seat
        outbound_seat = driver.find_element_by_css_selector(".planebody a.seat.infant:not(.reserved):not(.selected)")
    else:
        # select a non-reserved non-selected seat
        outbound_seat = driver.find_element_by_css_selector(".planebody a.seat:not(.reserved):not(.selected)")

    print("Passenger: %s, choosing seat: %s" % (outbound_passenger.text.strip(), outbound_seat.get_attribute("data-seat")))
    outbound_seat.click()

inbound_plan = wait.until(EC.visibility_of_element_located((By.XPATH, "/html/body/div[3]/form/div[1]/div/div[1]/div[15]/div[2]/div/div[2]/div[2]")))

#seats selection - inbound

for inbound_passenger in driver.find_elements_by_css_selector("ol[data-flightbound='Inbound'] li[data-personid]"):
    inbound_passenger.click()

#driver.find_elements_by_css_selector("ol.passengerlist li[data-personid]"):

    inbound_has_infant = inbound_passenger.get_attribute("data-hasinfant")

    # choose seats
    if inbound_has_infant:
        # select a non-selected infant seat
        inbound_seat = driver.find_element_by_css_selector(".planebody a.seat.infant:not(.reserved):not(.selected)")
    else:
        # select a non-reserved non-selected seat
        inbound_seat = driver.find_element_by_css_selector(".planebody a.seat:not(.reserved):not(.selected)")

    print("Passenger: %s, choosing seat: %s" % (inbound_passenger.text.strip(), inbound_seat.get_attribute("data-seat")))
    inbound_seat.click()
6
  • You mean the element is out of view due to scroll? Edit: My bad. You mean that the next seat plan still hasn't appeared, hence, not visible Commented Feb 13, 2016 at 19:52
  • When I have such issues, I always add a pretty big time.sleep, to check if it is a javascript changes DOM slower than Selenium checks it, or it is a my code select elements wrong way. One small advice, try to add id to the HTML tags, it will simply your selectors and debugging Commented Feb 13, 2016 at 20:07
  • @Obsidian Yes seems like it can't continue the clicking of the radio button because when we jump from outbound list to inbound list, the plane's seat plan changes from outbound to inbound and hence that brief moment causes the error Commented Feb 13, 2016 at 20:38
  • @NikolayGolub The time.sleep() didn't work. It's seems strange though Commented Feb 13, 2016 at 20:51
  • @BruceyBandit could you please post the complete code so that we can try reproducing the problem too? Also, on which line is it failing? Please post the traceback also. Thanks! Commented Feb 13, 2016 at 20:55

1 Answer 1

2

It could be that there is more than one inbound_seat and then when you run this code the element that Selenium returns is not the one you are expecting. Note that Selenium by default always returns the first element in case there are more than one.

# choose seats
if inbound_has_infant:
    # select a non-selected infant seat
    inbound_seat = driver.find_element_by_css_selector(".planebody a.seat.infant:not(.reserved):not(.selected)")
else:
    # select a non-reserved non-selected seat
    inbound_seat = driver.find_element_by_css_selector(".planebody a.seat:not(.reserved):not(.selected)")
Sign up to request clarification or add additional context in comments.

1 Comment

Ah yes you're right. I add an invisibility and visibility wait and then added .outbound and .inbound for outbound_seat and inbound_seat and it worked. Thank you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.