本文整理汇总了Python中selenium.webdriver.support.ui.Select.select_by_visible_text方法的典型用法代码示例。如果您正苦于以下问题:Python Select.select_by_visible_text方法的具体用法?Python Select.select_by_visible_text怎么用?Python Select.select_by_visible_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.ui.Select
的用法示例。
在下文中一共展示了Select.select_by_visible_text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dropdown_selection
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def test_dropdown_selection(self):
# Navegamos hasta la aplicacion
self.driver.get("http://the-internet.herokuapp.com/dropdown")
select = Select(self.driver.find_element_by_id("dropdown"))
select.select_by_visible_text("Option 2")
示例2: WebConfig
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def WebConfig(self):
self.pubmodul.location("/html/frameset/frameset/frame[2]")
select=Select(self.driver.find_element_by_id("glbl_ena"))
select.select_by_visible_text("Enabled")
age=str(random.randint(10,10000000))
self.driver.find_element_by_id("aging_enabled").click()
self.driver.find_element_by_id("aging_period").clear()
self.driver.find_element_by_id("aging_period").send_keys(age)
config = {}
config['age']=age
if self.prjName == 's3280':
j=9
if self.prjName == 's4140':
j=5
for i in range (1,j):
config[i]={}
ena=str("ena_%d"%i)
select1=Select(self.driver.find_element_by_id(ena))
select1.select_by_value("1")
limit_value=str(random.randint(1,1024))
limit=str("limit_%d"%i)
config[i]['limit']=limit_value
self.driver.find_element_by_id(limit).clear()
self.driver.find_element_by_id(limit).send_keys(limit_value)
action=str('action_%d'%i)
action_value=random.choice(['0','1','2','3'])
config[i]['action']=action_value
select2=Select(self.driver.find_element_by_id(action))
select2.select_by_value(action_value)
time.sleep(1)
self.driver.find_element_by_xpath("/html/body/form/p/input[2]").click()
time.sleep(2)
return config
示例3: makeselection
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def makeselection():
month = browser.find_element_by_xpath(".//a[contains(@onclick, 'jmpto1605')]")
month.send_keys("\n")
time.sleep(5) # delays for 5 seconds
sectionDatesOfStay = browser.find_element_by_id('sectionDatesOfStay')
containerDatesOfStay = sectionDatesOfStay.find_element_by_id('containerDatesOfStay')
calCell = containerDatesOfStay.find_element_by_class_name('calCell')
cal1 = calCell.find_element_by_id('cal1')
calTable1605 = cal1.find_element_by_id('calTable1605')
# Select May 28 as the arrival day
date_28 = calTable1605.find_element_by_id('160528')
date_28.send_keys("\n")
time.sleep(5) # delays for 5 seconds
# Select May 29 as the departure day
date_29 = calTable1605.find_element_by_id('160529')
date_29.send_keys("\n")
time.sleep(5) # delays for 5 seconds
# Select the adults number
frmNumAdults = browser.find_element_by_id('frmNumAdults')
adultNo = Select(frmNumAdults)
adultNo.select_by_visible_text('2')
# Check the room status
time.sleep(5)
suiteTypes = browser.find_element_by_id('suiteTypes')
sendemail()
示例4: select_multi_items
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def select_multi_items(self, select_name):
"""
Select multiple options from select with label (recommended), name, or
id. Pass a multiline string of options. e.g.
.. code-block:: gherkin
When I select the following from "Contact Methods":
\"\"\"
Email
Phone
Fax
\"\"\"
"""
# Ensure only the options selected are actually selected
option_names = self.multiline.split('\n')
select_box = find_field(world.browser, 'select', select_name)
assert select_box, "Cannot find a '{}' select.".format(select_name)
select = Select(select_box)
select.deselect_all()
for option in option_names:
try:
select.select_by_value(option)
except NoSuchElementException:
try:
select.select_by_visible_text(option)
except NoSuchElementException:
raise AssertionError("Cannot find option: '{}'.".format(option))
示例5: test_04_dep_bar_content
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def test_04_dep_bar_content(self):
chart_titles = ['VistA Packages Dependencies Chart','VistAPackageStatistics']
dep_chart_legend = ['depends','dependents']
dep_chart_top_entries = ['Kernel','Order Entry Results Reporting','Accounts Receivable']
global driver
# Ensure that the data and labels of chart are not empty
chart_container = driver.find_elements_by_class_name("highcharts-series")
for type in chart_container:
bar_array = type.find_elements_by_tag_name("rect")
self.assertTrue(len(bar_array) > 0)
chart_container = driver.find_elements_by_class_name("highcharts-data-labels")
for type in chart_container:
bar_array = type.find_elements_by_tag_name("text")
self.assertTrue(len(bar_array) > 0)
# Read title of graph
bar_chart = driver.find_element_by_id("bar-chart")
title_element = bar_chart.find_element_by_class_name("highcharts-title")
self.assertTrue(title_element.text in chart_titles)
# Ensure that legends have proper information
chart_legend = bar_chart.find_element_by_class_name("highcharts-legend")
legend_array = chart_legend.find_elements_by_tag_name("text")
for item in legend_array:
self.assertTrue(item.get_attribute("innerHTML") in dep_chart_legend)
# Check each of the "Sort By" selections to ensure that the first element is found in top_entries array
dep_pulldown = bar_chart.find_element_by_id("list-dep")
pulldown_options = Select(dep_pulldown)
for option in pulldown_options.options:
pulldown_options.select_by_visible_text(option.text)
self.assertTrue( driver.find_element_by_xpath("//*[@id='highcharts-0']/div/span[1]").text in dep_chart_top_entries)
time.sleep(5)
示例6: select_state
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def select_state(self, country):
select = Select(self.driver.find_element(*ShippingPageLocators.STATE_DROPDOWN))
if country==None:
random = randint(0,3)
select.select_by_index(state_number)
else:
select.select_by_visible_text(country)
示例7: boostme
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def boostme(driver,NotAmped,amptype,doubledipchoice):
if amptype=='DD':
for k,v in NotAmped.iteritems():
v.click()
time.sleep(SLEEP_SECONDS)
sele=Select(driver.find_element_by_xpath("//*[@id='secondPool']/div/div/div[2]/form/div/select"))
dropdown_options = sele.options
for available in range(0,len(dropdown_options)):
current_option=dropdown_options[available].text
if doubledipchoice==current_option:
sele.select_by_visible_text(current_option)
time.sleep(SLEEP_SECONDS)
break
SecondPoolDiv=driver.find_element_by_id("secondPool")
SecondPoolDiv.find_element_by_xpath(".//button[contains(text(), 'Add Pool')]").click()
time.sleep(SLEEP_SECONDS)
elif amptype=='Boost':
for k,v in NotAmped.iteritems():
v.click()
time.sleep(5)
示例8: getLinks
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def getLinks(topic, collection, driver):
startPage = "http://www.cochranelibrary.com/home/topic-and-review-group-list.html?page=topic"
# Clicking on given topic
driver.get(startPage)
# Loading the page
driver.find_element_by_link_text(topic).click()
# Waiting until page is loaded
numberSelector = WebDriverWait(driver, 1).until(
EC.presence_of_element_located((By.ID, "results_per_page_top"))
)
select = Select(numberSelector)
# Loading 100 element on the page
select.select_by_visible_text("100")
time.sleep(3)
# Gettin page number
pageNext = driver.find_element_by_class_name("results-block__pagination-list")
listPage = pageNext.find_elements_by_tag_name("li")
for i in range(len(listPage)-1):
getLinksSinglePage(collection, driver)
pageNext = driver.find_element_by_class_name("results-block__pagination-list")
listPage = pageNext.find_elements_by_tag_name("li")
# Click on next button
listPage[-1].click()
time.sleep(10)
示例9: test_drop_down
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def test_drop_down(self):
driver = self.driver
exp_options = [ "BMW", "Mercedes", "Audi", "Honda" ]
act_options = []
#Get the Dropdown as a Select using it's name attribute
make = Select(driver.find_element_by_name("make"))
#Verify Dropdown has four options for selection
self.assertEqual(4,len(make.options))
#Retrieve the option values from Dropdown using getOptions() method
for option in make.options:
act_options.append(option.text)
#Verify Dropdown has four options for selection
self.assertEqual(exp_options,act_options)
#With Select class we can select an option in Dropdown using Visible Text
make.select_by_visible_text("Honda")
self.assertEqual("Honda",make.first_selected_option.text)
#or we can select an option in Dropdown using value attribute
make.select_by_value("audi")
self.assertEqual("Audi",make.first_selected_option.text)
#or we can select an option in Dropdown using index
make.select_by_index("0")
self.assertEqual("BMW",make.first_selected_option.text)
示例10: add_dlpfile
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def add_dlpfile():
dlpdict= {"filenameNoIP":u"文件.txt"}
for key in dlpdict.keys():
login(driver,user,base_url)
dlpname = str(key)
value = dlpdict.get(key)
time.sleep(3)
yigou=driver.find_element_by_xpath(u"//span[contains(text(), '策略管理')]")
ActionChains(driver).move_to_element(yigou).perform()
driver.find_element_by_xpath("//a[@href='#/policy/manager']").click()
time.sleep(3)
driver.find_element_by_xpath(u"//div[contains(text(), 'DLP策略')]").click()
driver.find_element_by_xpath(u"//span[contains(text(), '新增')]").click()
driver.find_element_by_id("policyname").clear()
driver.find_element_by_id("policyname").send_keys("%s" %(dlpname))
time.sleep(2)
driver.find_element_by_xpath("(//button[@type='button'])[2]").click()
driver.find_element_by_xpath("(//button[@type='button'])[4]").click()
select = Select(driver.find_element_by_xpath(u"//select[contains(@id, 'policytype_')]"))
select.select_by_visible_text(u"文件名")
driver.find_element_by_xpath(u"//div[@class='col-md-8']/div[@class='form-group']/input").send_keys("%s" %(value))
time.sleep(3)
driver.find_element_by_xpath(u"//span[contains(text(),'生成安全事件')]").click()
driver.find_element_by_id("alertname").send_keys("%s" %(dlpname))
Select(driver.find_element_by_id("alertseverity")).select_by_visible_text(u"极度严重")
Select(driver.find_element_by_id("alertcategory")).select_by_visible_text(u"有害程序")
driver.find_element_by_css_selector("#alertcategory > option.ng-binding.ng-scope").click()
Select(driver.find_element_by_id("alertsubcategory")).select_by_visible_text(u"网页恶意代码")
driver.find_element_by_xpath(u"//div/button[contains(text(), '提交')]").click()
time.sleep(5)
示例11: add_in_group
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def add_in_group(self, contact, group):
wd = self.app.wd
self.open_home_page()
self.select_contact_by_id(contact.id)
select = Select(wd.find_element_by_name("to_group"))
select.select_by_visible_text(group.name)
wd.find_element_by_name("add").click()
示例12: set_experience
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def set_experience(self):
if len(self.driver.find_elements_by_css_selector(
'.recommended-section-experience > .recommended-section-add')) > 0:
self.driver.find_element_by_css_selector(
'.recommended-section-experience > .recommended-section-add').click()
elif len(self.driver.find_elements_by_css_selector('#background-experience > button')) > 0:
self.driver.find_element_by_css_selector('#background-experience > button').click()
else:
return False
time.sleep(1)
# company name
self.driver.find_element_by_css_selector('#companyName-positionCompany-position-editPositionForm').send_keys(
self.profile.organization)
time.sleep(1)
# title
self.driver.find_element_by_css_selector('#title-position-editPositionForm').send_keys(self.profile.title)
# time period
select = Select(self.driver.find_element_by_css_selector('#month-startDate-position-editPositionForm'))
select.select_by_visible_text(self.profile.start_month)
self.driver.find_element_by_css_selector('#year-startDate-position-editPositionForm').clear()
self.driver.find_element_by_css_selector('#year-startDate-position-editPositionForm').send_keys(
self.profile.start_year)
self.driver.find_element_by_css_selector('#isCurrent-endDate-position-editPositionForm').click()
self.driver.find_element_by_css_selector('#summary-position-editPositionForm').send_keys(
self.profile.description)
self.driver.find_element_by_css_selector('form[name=editPositionForm] > p > input').click()
示例13: test_editor_can_create_new_media_item
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def test_editor_can_create_new_media_item(self):
# Anthony logs into the site
self.log_in_editor()
# Anthony goes to the add new story page
self.browser.get(self.test_server + '/story/add/media')
# Anthony tries to save the media item without a title, but can't
self.browser.find_element_by_id('id_title').clear()
self.browser.find_element_by_name('submit').click()
self.assertIn('This field is required.', self.browser.find_element_by_class_name('help-block').text)
# Anthony makes some changes and saves.
self.browser.find_element_by_id('id_title').send_keys('Functional Test Add Media Title')
self.browser.find_element_by_class_name('redactor_editor').send_keys('This is an added paragraph to the create new story test.')
author = Select(self.browser.find_element_by_id('id_author'))
author.select_by_visible_text('anthony')
self.browser.find_element_by_id('id_tags').send_keys(', Tags, Media')
self.browser.find_element_by_name('submit').click()
# Anthony sees two success messages, saved and editor notified
self.assertIn('Media saved successfully',
self.browser.find_elements_by_class_name('alert-success')[0].text)
self.assertIn('Functional Test Add Media Title',
self.browser.find_element_by_tag_name('h2').text)
示例14: get_entries
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def get_entries(self):
selected = self.soup.find(class_="journal")
journal_select = Select(self.driver.find_element_by_id("journal"))
# getting rid of first "description" row
journal_gen = WileyScraper.__get_child_tag_strings(selected)
next(journal_gen)
for journal in journal_gen:
try:
journal_select.select_by_visible_text(journal)
except NoSuchElementException:
print "Couldn't find matching journal for input: " + str(journal)
continue
oa_option_element = self.driver.find_element_by_id("displayJOAP")
if (oa_option_element.text == "Fully Open Access") or (oa_option_element.text == "OpenChoice"):
try:
price = self.__get_price()
except MissingAttributeException:
print journal + ": Unable to find price"
continue
try:
issn_matches = self.__get_issn()
except MissingAttributeException:
print "Error: " + journal + "\n\t" + oa_option_element.text
continue
journal_type = "OA" if oa_option_element.text == "Fully Open Access" else "Hybrid"
yield self.to_unicode_row(["Wiley", journal, str(date.today()), journal_type, issn_matches, price])
示例15: _open_all_the_tables
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_visible_text [as 别名]
def _open_all_the_tables():
refresh_window(world)
pagers = get_elements(world.browser, class_attr="gridview", tag_name="table")
pagers = filter(lambda x : x.is_displayed(), pagers)
for pager in pagers:
elem = get_element(pager, class_attr="pager_info", tag_name="span")
m = re.match('^\d+ - (?P<from>\d+) of (?P<to>\d+)$', elem.text.strip())
do_it = False
if m is None:
do_it = True
else:
gp = m.groupdict()
do_it = gp['from'] != gp['to']
if do_it:
elem.click()
# we cannot select an unlimited number of items. So we stick to 500
# even if we know that the row we are looking for is in the next page... (comes from US-1207)
element = get_element(pager, tag_name="select", attrs=dict(action="filter"))
select = Select(element)
select.select_by_visible_text("500")
wait_until_not_loading(world.browser, wait="I cannot load the whole table")