1

I've been trying for about a week to figure out a drop down menu using selenium 2. It's a project I am working on to automate a flight search using ITA Matrix 2 (http://matrix.itasoftware.com/). Everything works OK except selecting the number of passengers from the drop down menu. Clicking on it works fine, but attempts to send keys or arrow commands to both it, and the new ID which is created when it pops up, don't result in any actions. I appreciate any help! (I am very new to python, I'm doing this project as a sort of self teaching exercise to learn).

from selenium import webdriver
from time import sleep
import time

driver = webdriver.Firefox()
driver.get("http://matrix.itasoftware.com/")


driver.find_element_by_id("advancedfrom1").send_keys(lport) #starting airport
driver.find_element_by_id("advancedto1").send_keys(rport) #destination airport
driver.find_element_by_id("advanced_rtDeparture").send_keys(ldate) #leaving date
driver.find_element_by_id("advanced_rtReturn").send_keys(rdate)    #return date
driver.find_element_by_id("ita_form_location_RouteLanguageTextBox_0").send_keys(lflight) #going flight number
driver.find_element_by_id("ita_form_location_RouteLanguageTextBox_1").send_keys(rflight) #return flight number

#problem code:


driver.find_element_by_id("ita_form_pax_Passenger_0").click()#.send_keys("2")
time.sleep(2)  #allow drop down to pop up

from selenium.webdriver.common.keys import Keys
driver.find_element_by_id("dijit_MenuItem_4_text").send_keys(Keys.DOWN)  #tried to scroll down
driver.find_element_by_id("ita_form_pax_Passenger_0").send_keys(Keys.DOWN)
#also tried just sending the number directly:
driver.find_element_by_id("dijit_MenuItem_4_text").send_keys(numpax)
driver.find_element_by_id("ita_form_pax_Passenger_0").send_keys(numpax)
2
  • +1 for matrix.itasoftware.com Commented Nov 21, 2011 at 16:43
  • Did you have any luck with matrix? I'm working on the same thing... Commented Jan 4, 2012 at 1:37

1 Answer 1

2

In this case, it fails because the passenger drop down menu is not actually a drop down menu, it's some clever html and javascript so it won't respond to the usual events as expected.

Try this: Click on the list at ID:

ita_form_pax_Passenger_0

Then click the menu item at XPath (replace 'NUMBER_OF_PASSENGERS' with the number of passengers):

//td[contains(@id,'dijit_MenuItem')][text()='NUMBER_OF_PASSENGERS']
Sign up to request clarification or add additional context in comments.

1 Comment

a little late getting back to you (just merged an old account). But I believe this helped back then and I wanted to thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.