本文整理汇总了Python中selenium.webdriver.support.select.Select类的典型用法代码示例。如果您正苦于以下问题:Python Select类的具体用法?Python Select怎么用?Python Select使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Select类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EditAddOrganiztionPageCMS
class EditAddOrganiztionPageCMS(BasePageCMS):
def __init__(self, driver, wait):
self.driver = driver
self.wait = wait
self.name = self.wait.until(lambda driver : driver.find_element_by_id("id_name"))
self.parent = Select(self.wait.until(lambda driver : driver.find_element_by_id("id_parent")))
self.lmSite = Select(self.wait.until(lambda driver : driver.find_element_by_id("id_lmsite")))
def typeName(self, name):
self.name.send_keys(name)
def selectParent(self, parent):
self.parent.select_by_visible_text(parent)
def selectLmSite(self, site):
self.lmSite.select_by_visible_text(site)
def clickSaveAndContinueEditingButton(self):
self.clickSaveAndContinueEditing()
return EditAddOrganiztionPageCMS(self.driver, self.wait)
def getName(self):
return self.name.get_attribute("value")
def getSelectedParent(self):
return self.parent.first_selected_option.text
def getSelectedLmSite(self):
return self.lmSite.first_selected_option.text
def clickObjectPermissions(self):
self.clickOnLink("Object permissions")
return OrganizationObjectPermissionsCMS(self.driver, self.wait)
示例2: chooseSelectElement
def chooseSelectElement(self, fieldName, fieldText):
"""
Chooses one of the elements in a select list, by its visible text
"""
select = Select(self.driver.find_element_by_name(fieldName));
#select.deselect_all()
select.select_by_visible_text(fieldText)
示例3: select_option_by_value
def select_option_by_value(browser_query, value):
"""
Selects a html select element by matching value attribute
"""
select = Select(browser_query.first.results[0])
select.select_by_value(value)
def options_selected():
"""
Returns True if all options in select element where value attribute
matches `value`. if any option is not selected then returns False
and select it. if value is not an option choice then it returns False.
"""
all_options_selected = True
has_option = False
for opt in select.options:
if opt.get_attribute('value') == value:
has_option = True
if not opt.is_selected():
all_options_selected = False
opt.click()
# if value is not an option choice then it should return false
if all_options_selected and not has_option:
all_options_selected = False
return all_options_selected
# Make sure specified option is actually selected
EmptyPromise(options_selected, "Option is selected").fulfill()
示例4: DashboardPageCMS
class DashboardPageCMS(BasePageCMS):
def __init__(self, driver, wait, noPageLoad=None):
self.driver = driver
self.wait = wait
if(noPageLoad==None):
self.driver.get(ServerRelated().serverToBeTested() + "admin/cms/contentproject/dashboard/")
self.uploadDropdown = Select(self.wait.until(lambda driver : driver.find_element_by_id("id_upload_media")))
self.createDropdown = Select(self.wait.until(lambda driver : driver.find_element_by_id("id_create_content")))
def selectUploadMediaByText(self, media):
self.uploadDropdown.select_by_visible_text(media)
def selectCreateUser(self):
self.createDropdown.select_by_visible_text("User")
return OrganizationUsersPageCMS(self.driver, self.wait)
def getNumberOfVisibleContentProjects(self):
self.contProjects = self.wait.until(lambda driver : driver.find_elements_by_xpath("//li[contains(text(),'Content Projects')]/ul/li"))
return len(self.contProjects)
def clickModifyStationModule(self):
self.clickOnLink("Modify Station Module")
return EditAddStationModulePageCMS(self.driver, self.wait)
def clickUsersLink(self):
self.clickOnLink("Users")
return OrganizationUsersPageCMS(self.driver, self.wait)
def getTitlesFromDashboard(self):
dashboardTitles = self.wait.until(lambda driver : driver.find_elements_by_xpath("//tbody[@id='content_items_table_body']/tr/td[@class='original']"))
titles = []
for element in dashboardTitles:
titles.append(element.text)
return titles
示例5: downloadChunk
def downloadChunk( link, browser, rFrom, rTo, i ):
try :
close = browser.find_element_by_xpath("//a[@class='quickoutput-cancel-action']") #close previous download box
close.click()
except :
pass
fFrom = str(rFrom)
rTo = str(rTo)
browser.execute_script("window.scrollTo(0, 0);")
#time.sleep(1)
browser.find_element_by_xpath("//div[@id='s2id_saveToMenu']//b").click() #save to arrow
if i == 1:
browser.find_element_by_id('select2-result-label-12').click() #save to other formats
else :
browser.find_element_by_id('select2-chosen-1').click() #save to other formats
browser.find_element_by_id('numberOfRecordsRange').click() #select records range
browser.find_element_by_id('markFrom').click() #click on from box
browser.find_element_by_id('markFrom').send_keys(fFrom) #enter keys in from box
browser.find_element_by_id('markTo').click() #click on to box
browser.find_element_by_id('markTo').send_keys(rTo) #enter keys in to box
dropdown = browser.find_element_by_id('bib_fields') #find fields dropdown
select_box = Select(dropdown)
select_box.select_by_index(3) #select option 3 (all records and refs)
browser.find_element_by_xpath("//span[@class='quickoutput-action']").click() #click send
示例6: select_version_by_index
def select_version_by_index(self, index):
'''
Select the version of the application you want to report on
'''
version_dropdown = self.find_element(*self._all_versions_locator)
select = Select(version_dropdown)
select.select_by_index(index)
示例7: select_product
def select_product(self, application):
'''
Select the Mozilla Product you want to report on
'''
element = self.find_element(*self._product_select_locator)
select = Select(element)
return select.select_by_visible_text(application)
示例8: select_from_list
def select_from_list(self, element=None, value=None):
locator, _type = element
if not self.wait_element(element):
allure.attach('screenshot', self.driver.get_screenshot_as_png(), type=AttachmentType.PNG)
pytest.fail("element {} not found".format(locator))
select = Select(self.driver.find_element(by=_type, value=locator))
select.select_by_value(value)
示例9: add_to_group
def add_to_group(self, contact, group):
wd = self.app.wd
self.load_home_page()
self.select_by_id(contact.id)
select = Select(wd.find_element_by_name("to_group"))
select.select_by_visible_text(group.name.strip())
wd.find_element_by_name("add").click()
示例10: fill_payments_form
def fill_payments_form(payments_form,
first_name,
last_name,
gender,
phone_number,
email_address,
# birthday_date
):
"""
Function for fill up payments form.
Params:
# first_name,
# last_name,
# gender - value "mrs" means female and "mr" means male,
# phone_number,
# email_address.
"""
# birthday_date
# """
_genders = [u"mrs", u"mr"]
if not gender in _genders:
raise Exception('Bad gender value %s - please choose from %s' % (gender, _genders))
payments_form.find_element_by_id("bookFlight_paxes_1_name").send_keys(first_name)
payments_form.find_element_by_id("bookFlight_paxes_1_surname").send_keys(last_name)
gender_select = Select(payments_form.find_element_by_id("bookFlight_paxes_1_title"))
gender_select.select_by_value(gender)
payments_form.find_element_by_id("bookFlight_contactDetails_phoneNumber_phoneNumber")\
.send_keys(phone_number)
payments_form.find_element_by_id("bookFlight_contactDetails_email").send_keys(email_address)
payments_form.find_element_by_id("bookFlight_statute").click()
示例11: add_advanced_filter
def add_advanced_filter(self, key: str, value: str) -> None:
"""Add a new advanced filter"""
# Toggle the filter panel if it is not open yet
self.toggle_selected_advanced_filters(display=True)
# Select the last <select> available
filter_row_xpath = '(//div[contains(@class, "selected-advanced-filters")]/div[contains(@class, "js-filter-item")])[last()]'
filter_row = self.findBy('xpath', filter_row_xpath)
filter_select_xpath = f'//select[contains(@class, "filter-key-select")]'
select = Select(self.findBy('xpath', filter_select_xpath, base=filter_row))
# If it already has a key selected, click "add filter" to add a new row
# and select the <select> again
if select.first_selected_option.text != '---':
self.findBy('id', 'filter-add-new').click()
filter_row = self.findBy('xpath', filter_row_xpath)
select = Select(
self.findBy('xpath', filter_select_xpath, base=filter_row))
# Select the key, wait for the values to be loaded and select one
select.select_by_value(key)
self.wait_for('xpath', filter_row_xpath + '//div[contains(@class, "loading-indicator-filter-key")]', visibility=False)
self.findBy('xpath', f'//div[contains(@class, "filter-value-column")]//input[@value="{value}"]', base=filter_row).click()
self.apply_filter()
示例12: select_report
def select_report(self, report_name):
"""
Select the report type from the drop down
and wait for the page to reload
"""
report_dropdown = self.selenium.find_element(*self._report_select_locator)
select = Select(report_dropdown)
select.select_by_visible_text(report_name)
if "Top Crashers" == report_name:
from pages.crash_stats_top_crashers_page import CrashStatsTopCrashers
return CrashStatsTopCrashers(self.testsetup)
elif "Top Crashers by TopSite" == report_name:
from pages.crash_stats_top_crashers_by_site_page import CrashStatsTopCrashersBySite
return CrashStatsTopCrashersBySite(self.testsetup)
elif "Crashes per User" == report_name:
from pages.crash_stats_per_active_daily_user_page import CrashStatsPerActiveDailyUser
return CrashStatsPerActiveDailyUser(self.testsetup)
elif "Nightly Builds" == report_name:
from pages.crash_stats_nightly_builds_page import CrashStatsNightlyBuilds
return CrashStatsNightlyBuilds(self.testsetup)
elif "Top Changers" == report_name:
from pages.crash_stats_top_changers_page import CrashStatsTopChangers
return CrashStatsTopChangers(self.testsetup)
示例13: do_speller
def do_speller (self):
driver = self.driver
answer_dict = self.answer_dict
speller_url = self.url + self.assignment_number + '/speller'
driver.get(speller_url)
select_speed = Select(driver.find_element_by_id('speller-prompt'))
select_speed.select_by_visible_text("Don't Speak")
try:
alert = driver.switch_to_alert()
alert.accept()
except NoAlertPresentException:
pass
driver.implicitly_wait(3)
counter = 0
while True:
try:
driver.implicitly_wait(3)
question=driver.find_element_by_css_selector("*[class^='qDef lang-en TermText']").text
inputA = driver.find_element_by_id('speller-inp')
time.sleep(.5)
try: # this throws an exception when its done
inputA.click()
except: #specify element is not visible exception
self.speak_remainder.run('Finished Speller')
break
inputA.clear()
inputA.send_keys(answer_dict[question])
inputA.send_keys(Keys.RETURN)
driver.get(speller_url)
completed = driver.find_element_by_id('overall-percent').text
try:
completed = int(completed.replace('%', ''))
if completed % 10 == 0 and completed != 0:
phrase = completed + ' completed'
self.speak_remainder.run(phrase)
except ValueError:
continue
except TypeError:
continue
except TimeoutException:
print 'Timeout'
continue
except NoSuchElementException:
counter += 1
try:
if driver.find_element_by_id('game-over').text != "":
self.speak_remainder.run('Finished Speller')
break
except NoSuchElementException:
continue
if counter == 3:
print 'stuck'
else:
print 'Reloading'
continue
示例14: select_drop_down
def select_drop_down(self, drop_down_locator, value):
element = self.find_clickable_element(drop_down_locator)
if element:
my_select = Select(element)
my_select.select_by_value(value)
else:
raise Exception('Unable to find drop down with locator %s' % str(drop_down_locator))
示例15: create_run
def create_run(self, name='Test Run', product_version='Test Product Test Version', desc='This is a test run', start_date='2011-01-01', end_date='2012-12-31', suite_list=None, series_run=False):
dt_string = datetime.utcnow().isoformat()
run = {}
run['name'] = u'%(name)s %(dt_string)s' % {'name': name, 'dt_string': dt_string}
run['desc'] = u'%(desc)s created on %(dt_string)s' % {'desc': desc, 'dt_string': dt_string}
run['series'] = series_run
run['manage_locator'] = (self._run_manage_locator[0], self._run_manage_locator[1] % {'run_name': run['name']})
run['homepage_locator'] = (self._run_homepage_locator[0], self._run_homepage_locator[1] % {'run_name': run['name']})
run['run_tests_locator'] = self._run_tests_button_locator
name_field = self.selenium.find_element(*self._name_locator)
name_field.send_keys(run['name'])
series_element = self.selenium.find_element(*self._series_run_locator)
if series_element.is_selected():
if not series_run:
series_element.click()
else:
if series_run:
series_element.click()
product_version_select = Select(self.selenium.find_element(*self._product_version_select_locator))
product_version_select.select_by_visible_text(product_version)
self.selenium.find_element(*self._description_locator).send_keys(run['desc'])
self.type_in_element(self._start_date_locator, start_date)
self.selenium.find_element(*self._end_date_locator).send_keys(end_date)
if suite_list:
self.multiselect_widget.include_items(suite_list)
self.selenium.find_element(*self._submit_locator).click()
return run