我一直在嘗試約一個星期來找出使用硒2的下拉菜單。這是一個項目,我正在努力使用ITA矩陣2自動化的航班搜索(http:///matrix.itasoftware.com/)。除了從下拉菜單中選擇乘客人數外,一切正常。點擊它可以正常工作,但是嘗試將密鑰或箭頭命令發送給它以及彈出時創建的新ID不會導致任何操作。我感謝任何幫助! (我對python非常陌生,我將這個項目作爲一種自我教學練習來學習)。與硒2的下拉菜單2
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)
+1 matrix.itasoftware.com – Anders
你有沒有與矩陣運氣?我正在做同樣的事情... –