Instantly share code, notes, and snippets.

@sunjeet-khokhar sunjeet-khokhar/ Secret
Created Jan 9, 2018

What would you like to do?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
import time
from import By
from import WebDriverWait
from import expected_conditions as EC
from import Select
# for easy future changes and code maintainbility i have added all the locators and parameters like username/password at the top of the test
driver = webdriver.Chrome()
CONTINUE_BUTTON = (By.XPATH,'//*[@id="cms-search-panel-container"]/div/div/div/form/div[3]/div/button')
FLIGHT_CLASS_DROPDOWN = (By.ID,'serviceclass')
URL = ''
class AirNZ_flight_class:
def verify_flight_class_dropdown_value(self):
# wait for the continue button to appear
continue_button = WebDriverWait(driver,10).until(EC.presence_of_element_located(CONTINUE_BUTTON))
# wait for the fligh class dropdown to appear
flight_class_dropdown = WebDriverWait(driver,10).until(EC.presence_of_element_located(FLIGHT_CLASS_DROPDOWN))
#select the drop down using the Select class imported from from
select = Select(flight_class_dropdown)
# select an option from the drop down based on a value, i did not go for a index in case the index changes due to addition or removal of entries
except(NoSuchElementException,TimeoutException) as e:
# fail the Test if the element can not be found or timeout occurs
print('Test failed, the flight class drop down could not be found ')
test = AirNZ_flight_class()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment