我遇到了一个问题,我正试图实施。所有这一切的拳头都没有认识到Select(pax_one_ob_meal)
这让我觉得我可能正试着打电话给<select
&gt;在这个实例中标记错误,但实际上我正在尝试编写一个执行以下操作的条件:
检查no_thanks
按钮是否显示或可见,如果是,则执行自助餐中的所有操作,然后检查yes_insurance
是否显示或可见如果是,则执行保险操作,然后点击“继续”按钮driver.find_element_by_name('ctl00$MainContent$forwardButton')
。
如果没有no_thanks
按钮,请检查是否有yes_insurance
,如果是,请执行保险操作,然后点击“继续”按钮。
如果没有no thanks
按钮,也没有显示yes_insurance
,则只需点击“继续”按钮即可。
我是否需要在if和else if语句中实现多个条件?有人可以给我一个如何在python中实现它的例子吗?
以下是我此刻尝试的内容:
#meals dropdowns
pax_one_ob_meal = driver.find_element_by_id("ctl00_MainContent_InFlightMeal_PassengerGridView_ctl02_mealsDropDown")
pax_one_ib_meal = driver.find_element_by_id("ctl00_MainContent_InFlightMeal_PassengerGridView_ctl02_mealsDropDownIn")
pax_two_ob_meal = driver.find_element_by_id("ctl00_MainContent_InFlightMeal_PassengerGridView_ctl03_mealsDropDown")
pax_two_ib_meal = driver.find_element_by_id("ctl00_MainContent_InFlightMeal_PassengerGridView_ctl03_mealsDropDownIn")
pax_three_ob_meal = driver.find_element_by_id("ctl00_MainContent_InFlightMeal_PassengerGridView_ctl04_mealsDropDown")
pax_three_ib_meal = driver.find_element_by_id("ctl00_MainContent_InFlightMeal_PassengerGridView_ctl04_mealsDropDownIn")
pax_four_ob_meal = driver.find_element_by_id("ctl00_MainContent_InFlightMeal_PassengerGridView_ctl05_mealsDropDown")
pax_four_ib_meal = driver.find_element_by_id("ctl00_MainContent_InFlightMeal_PassengerGridView_ctl05_mealsDropDownIn")
no_thanks = driver.find_element_by_id("ctl00_MainContent_InFlightMeal_removeMealButton")
#insurance
yes_insurance = driver.find_element_by_id('ctl00_MainContent_TravelInsuranceView_insuranceRequiredYes')
single_trip = driver.find_element_by_xpath('//input[@id="ctl00_MainContent_TravelInsuranceView_insuranceProduct1" and not(@disabled)]')
if no_thanks.is_displayed():
Select(pax_one_ob_meal)
pax_one_ob_meal.select_by_index(0)
wait.until(EC.element_to_be_clickable((By.ID, "ctl00_MainContent_InFlightMeal_PassengerGridView_ctl02_mealsDropDown")))
Select(pax_one_ib_meal)
pax_one_ib_meal.select_by_index(2)
wait.until(EC.element_to_be_clickable((By.ID, "ctl00_MainContent_InFlightMeal_PassengerGridView_ctl02_mealsDropDownIn")))
Select(pax_two_ob_meal)
pax_two_ob_meal.select_by_index(1)
wait.until(EC.element_to_be_clickable((By.ID, "ctl00_MainContent_InFlightMeal_PassengerGridView_ctl03_mealsDropDown")))
Select(pax_two_ib_meal)
pax_two_ib_meal.select_by_index(1)
wait.until(EC.element_to_be_clickable((By.ID, "ctl00_MainContent_InFlightMeal_PassengerGridView_ctl03_mealsDropDownIn")))
Select(pax_three_ob_meal)
pax_three_ob_meal.select_by_index(2)
wait.until(EC.element_to_be_clickable((By.ID, "ctl00_MainContent_InFlightMeal_PassengerGridView_ctl04_mealsDropDown")))
Select(pax_three_ib_meal)
pax_three_ib_meal.select_by_index(1)
wait.until(EC.element_to_be_clickable((By.ID, "ctl00_MainContent_InFlightMeal_PassengerGridView_ctl04_mealsDropDownIn")))
Select(pax_four_ob_meal)
pax_four_ob_meal.select_by_index(0)
wait.until(EC.element_to_be_clickable((By.ID, "ctl00_MainContent_InFlightMeal_PassengerGridView_ctl05_mealsDropDown")))
Select(pax_four_ib_meal)
pax_four_ib_meal.select_by_index(1)
wait.until(EC.element_to_be_clickable((By.ID, "ctl00_MainContent_InFlightMeal_PassengerGridView_ctl05_mealsDropDownIn")))
elif yes_insurance.is_displayed():
yes_insurance.click()
single_trip.click()
driver.find_element_by_xpath('//span[@id="insurance-button-submit" and (@disabled="false")]')
driver.find_element_by_id('ctl00_MainContent_TravelInsuranceView_InsuranceSubmitButton').click()
wait.until(EC.invisibility_of_element_located((By.ID, "ct100_MainContent_PageTransitionDialog_messageWrapper")))
wait.until(EC.element_to_be_clickable((By.ID, "ctl00_MainContent_forwardButton"))).click()
else:
driver.find_element_by_name('ctl00$MainContent$forwardButton')
以下是no_thanks
,yes_insurance
的HTML标记和继续按钮:
不,谢谢
<input type="submit" class="buttonnomeals" title="No thanks!" id="ctl00_MainContent_InFlightMeal_removeMealButton" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$InFlightMeal$removeMealButton", "", true, "", "", false, false))" value="No thanks!" name="ctl00$MainContent$InFlightMeal$removeMealButton">
保险
<input type="radio" value="insuranceRequiredYes" name="ctl00$MainContent$TravelInsuranceView$insuranceRequired" id="ctl00_MainContent_TravelInsuranceView_insuranceRequiredYes">
继续
<input type="submit" class="buttonforward" title="Checkout" id="ctl00_MainContent_forwardButton" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$forwardButton", "", true, "", "", false, false))" value="Checkout" name="ctl00$MainContent$forwardButton">