本文整理汇总了Python中selenium.webdriver.support.ui.Select.select_by_value方法的典型用法代码示例。如果您正苦于以下问题:Python Select.select_by_value方法的具体用法?Python Select.select_by_value怎么用?Python Select.select_by_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.ui.Select
的用法示例。
在下文中一共展示了Select.select_by_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WebConfig
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [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
示例2: test_delta_scan_live
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def test_delta_scan_live(base_url, selenium):
"""Quickly test a delta scan."""
selenium.get(base_url)
new_scan_link = selenium.find_element_by_id('new-scan')
new_scan_link.click()
# TODO: Rename field buttons
collapsed_scanners = selenium.find_element_by_css_selector(
'a[href*=collapse-deformField2')
collapsed_scanners.click()
nmap_options = selenium.find_element_by_name('nmap_options')
nmap_options.send_keys(PING_SWEEP)
scanner_a = Select(selenium.find_element_by_name('scanner_a'))
scanner_a.select_by_value('external')
scanner_b = Select(selenium.find_element_by_name('scanner_b'))
scanner_b.select_by_value('dmzscanner')
scan_target = selenium.find_element_by_name('scan_target')
scan_target.send_keys('203.0.113.1')
scan_target.submit()
time.sleep(5)
scan_results = selenium.find_element_by_id('external-results').text
assert '<address addr="203.0.113.1" addrtype="ipv4"/>' not in scan_results
scan_results = selenium.find_element_by_id('dmzscanner-results').text
assert '<address addr="203.0.113.1" addrtype="ipv4"/>' in scan_results
示例3: submit_form
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def submit_form(self, form, data, clear=True, submit=True, wait=True):
for k, v in data.items():
input_field = form.find_element_by_name(k)
if input_field.tag_name in ('input', 'textarea'):
field_type = input_field.get_attribute('type')
if field_type == 'radio':
radio_button = form.find_element_by_css_selector(
"input[type=radio][name={}][value='{}']".format(
k, v
)
)
radio_button.click()
elif field_type == 'checkbox':
checkbox_button = form.find_element_by_css_selector(
'input[type=checkbox][name={}]'.format(k)
)
if v and not checkbox_button.is_selected():
checkbox_button.click()
elif not v and checkbox_button.is_selected():
checkbox_button.click()
elif clear and input_field.get_attribute('value'):
input_field.clear()
input_field.send_keys(v)
elif input_field.tag_name == 'select':
select_field = Select(input_field)
select_field.select_by_value(v)
if submit:
submit_btn = form.find_element_by_xpath(
'.//button[@type="submit"]')
submit_btn.click()
if wait:
self.wait_for_page_load()
示例4: select_multi_items
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [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: body
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def body(self):
# Load Shabbat TOC and scroll to bottom
self.nav_to_text_toc(["Talmud"], "Shabbat").scroll_nav_panel_to_bottom()
# Check that DL Button is visible and not clickable
visible = self.driver.execute_script(
'var butt = document.getElementsByClassName("downloadButtonInner")[0]; ' + \
'var butt_bot = butt.getBoundingClientRect().top + butt.getBoundingClientRect().height; ' + \
'var win_height = window.innerHeight; ' + \
'return win_height > butt_bot;'
)
assert visible, "Download button below page"
# This isn't sufficient - it only checks if it's visible in the DOM
# WebDriverWait(self.driver, TEMPER).until(visibility_of_element_located((By.CSS_SELECTOR, ".downloadButtonInner")))
WebDriverWait(self.driver, TEMPER).until(
invisibility_of_element_located((By.CSS_SELECTOR, '.dlVersionFormatSelect + a')))
# Select version and format
select1 = Select(self.driver.find_element_by_css_selector('.dlVersionTitleSelect'))
select1.select_by_value("Wikisource Talmud Bavli/he")
select2 = Select(self.driver.find_element_by_css_selector('.dlVersionFormatSelect'))
select2.select_by_value("csv")
# Check that DL button is clickable
WebDriverWait(self.driver, TEMPER).until(
visibility_of_element_located((By.CSS_SELECTOR, '.dlVersionFormatSelect + a')))
示例6: run
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def run(self):
# Load Shabbat TOC and scroll to bottom
self.load_text_toc("Shabbat").scroll_nav_panel_to_bottom()
# Check that DL Button is visible and not clickable
visible = self.driver.execute_script(
'var butt = $(".downloadButtonInner"); ' +\
'var butt_bot = butt.offset().top + butt.height(); ' +\
'var win_height = $(window).height(); ' +\
'return win_height > butt_bot;'
)
assert visible, "Download button below page"
# This isn't sufficient - it only checks if it's visible in the DOM
#WebDriverWait(self.driver, TEMPER).until(visibility_of_element_located((By.CSS_SELECTOR, ".downloadButtonInner")))
WebDriverWait(self.driver, TEMPER).until(invisibility_of_element_located((By.CSS_SELECTOR, '.dlVersionFormatSelect + a')))
# Select version and format
s1 = Select(self.driver.find_element_by_css_selector('.dlVersionTitleSelect'))
s1.select_by_value("Wikisource Talmud Bavli/he")
s2 = Select(self.driver.find_element_by_css_selector('.dlVersionFormatSelect'))
s2.select_by_value("csv")
# Check that DL button is clickable
WebDriverWait(self.driver, TEMPER).until(visibility_of_element_located((By.CSS_SELECTOR, '.dlVersionFormatSelect + a')))
示例7: select
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def select(self, option=None, value=None, name=None, id=None, xpath=None, css=None):
how = None
what = None
selector = None
if name:
what = name
how = By.NAME
selector = 'name'
elif id:
what = id
how = By.ID
selector = 'id'
elif xpath:
what = xpath
how = By.XPATH
selector = 'xpath'
elif css:
what = css
how = By.CSS_SELECTOR
selector = 'css'
else:
raise ValueError("No valid selector passed (name, id, xpath or css)")
elem = self.find_element(by=how, value=what)
select = Select(elem)
if value:
print "SELECT value = " + value + " IN " + selector + " = " + what
select.select_by_value(value)
elif option:
print "SELECT option = " + str(option) + " IN " + selector + " = " + what
select.select_by_visible_text(option)
else:
raise ValueError("No option or value passed")
示例8: _click_download
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def _click_download(proj_id, driver):
driver.refresh()
proj_select = Select(driver.find_element_by_css_selector('[name=project]'))
proj_select.select_by_value(str(proj_id))
driver.find_element_by_id('react-tabs-8').click()
driver.wait_for_xpath("//a[text()='Download']").click()
time.sleep(0.5)
示例9: engineConfigLog
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def engineConfigLog(self,srvaddr):
print "\n========engineConfig========"
self.PubModuleEle.location("/html/frameset/frameset/frame[1]")
time.sleep(2)
self.driver.find_element_by_xpath("/html/body/form/table/tbody/tr[2]/td/ul/li/a").click()# locate Configuration
time.sleep(2)
self.driver.find_element_by_xpath("/html/body/form/table/tbody/tr[2]/td/ul/li/div/ul/li/a").click()#locate System
time.sleep(2)
self.driver.find_element_by_xpath("/html/body/form/table/tbody/tr[2]/td/ul/li/div/ul/li/div/ul/li[6]/a").click()# locate log
time.sleep(2)
print "***********ConfigurationFinish*************"
self.PubModuleEle.location("/html/frameset/frameset/frame[2]")
time.sleep(2)
WebDriverWait(self.driver, 30).until(lambda driver :driver.find_element_by_name("server_mode"))
select = Select(self.driver.find_element_by_name("server_mode"))
select.select_by_value("1")
elem=self.driver.find_element_by_xpath("/html/body/form/table/tbody/tr[2]/td[2]/input")
elem.clear()
self.driver.find_element_by_xpath("/html/body/form/table/tbody/tr[2]/td[2]/input").send_keys(srvaddr)
s1=self.driver.find_element_by_name("server_addr").get_attribute("value")
print "the serveraddr is %s"%s1
WebDriverWait(self.driver, 30).until(lambda driver :driver.find_element_by_name("syslog_level"))
select = Select(self.driver.find_element_by_name("syslog_level"))
select.select_by_value("0")
self.driver.find_element_by_xpath( "/html/body/form/p/input").click()
示例10: _select
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def _select(browser, text, index=0):
def is_clickable(browser):
elems = browser.find_elements_by_css_selector('.celltoolbar select')
if len(elems) <= index:
return False
elem = elems[index]
return elem.is_displayed and elem.is_enabled
def is_option(browser):
elem = browser.find_elements_by_css_selector('.celltoolbar select')[index]
select = Select(elem)
options = [x.get_attribute('value') for x in select.options]
return text in options
_wait(browser).until(is_clickable)
_wait(browser).until(is_option)
elem = browser.find_elements_by_css_selector('.celltoolbar select')[index]
select = Select(elem)
select.select_by_value(text)
def selected(browser):
elem = browser.find_elements_by_css_selector('.celltoolbar select')[index]
return elem.get_attribute('value') == text
_wait(browser).until(selected)
示例11: parse
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def parse(self, response):
self.br.get(response.url)
username=self.br.find_element_by_id('dnn_ctr3337_View_ctl00_tbUserName')
username.send_keys(USERNAME)
pwd=self.br.find_element_by_id('dnn_ctr3337_View_ctl00_tbPassword')
pwd.send_keys(PASSWORD)
sub=self.br.find_element_by_id('dnn_ctr3337_View_ctl00_btnSignIn')
sub.click()
time.sleep(1)
el=self.br.find_element_by_id('dnn_ctr4356_ViewJobBank_Candidate_lb_JobSearch')
el.click()
time.sleep(1)
subfield=Select(self.br.find_element_by_id('dnn_ctr4356_ViewJobBank_JobSearch_dl_Subfield'))
subfield.select_by_value(SUBFIELD)
el=self.br.find_element_by_id('dnn_ctr4356_ViewJobBank_JobSearch_btn_Submit')
el.click()
time.sleep(1)
# loop over pages
hxs=Selector(text=self.br.page_source,type='html')
pages=hxs.xpath('//td[contains(@class,"rgPagerCell")]//div[contains(@class,"rgNumPart")]//a/@href')
for idx in range(1,len(pages)+1):
page_link=self.br.find_element_by_xpath('//td[contains(@class,"rgPagerCell")]//div[contains(@class,"rgNumPart")]//a[%s]'%idx)
page_link.click()
time.sleep(3)
hxs=Selector(text=self.br.page_source,type='html')
rows=hxs.xpath('//table[@class="rgMasterTable"]/tbody/tr')
outframe=[{"link":i.xpath("td[2]//a/@href").extract()[0],
"date":str(i.xpath("td[6]//text()").extract()[0])}
for i in rows]
for idx,i in enumerate(outframe):#enumerate(out[0:3]): # for testing
request=scrapy.Request(outframe[idx]['link'],self.after_parse)
request.meta['post_date']=outframe[idx]['date']
logging.debug("requesting: %s"%request.url)
yield request
示例12: login
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def login(driver, user, passwd,app_key):
driver.get('https://login.taobao.com/member/login.jhtml?redirectURL=http://clouddata.taobao.com/ide/data.htm?spm=0.0.0.0.Zrhz8L&sub=true')
print driver.title.encode('utf-8')
driver.execute_script("document.querySelector('#J_SafeLoginCheck').click();")
# driver.find_element_by_id('J_SafeLoginCheck').click()
driver.execute_script("document.querySelector('#TPL_username_1').value= '%s';" % user)
driver.execute_script("document.querySelector('#TPL_password_1').value= '%s';" % passwd)
driver.execute_script("document.querySelector('#J_SubmitStatic').click();")
# driver.find_element_by_id('TPL_username_1').send_keys(user)
# driver.find_element_by_id('TPL_password_1').send_keys(passwd)
# driver.find_element_by_id('J_SubmitStatic').click()
wait = ui.WebDriverWait(driver, 30)
wait.until(lambda driver:driver.find_element_by_css_selector("#settings > div.w_con > div > form > table > tbody > tr:nth-child(3) > td:nth-child(2) > input:nth-child(1)").is_displayed())
print driver.title.encode('utf-8')
if app_key is None or not app_key.strip():
return
print "app_key: %s" % app_key
if(u'聚石塔数据引擎 - 用户设置' in driver.title):
#选择合适的app_key
select=Select(driver.execute_script("return document.querySelector('#J_app_list')"))
# select.find_element_by_xpath("//option[@value='%s']" % app_key).click()
select.select_by_value(app_key)
driver.find_element_by_css_selector("#settings > div.w_con > div > form > table > tbody > tr:nth-child(3) > td:nth-child(2) > input:nth-child(1)").click()
示例13: select
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def select(self, target, value):
"""
Select an option of a select box.
@param target: a element locator pointing at a select element
@param value: an option locator which points at an option of the select element
Option locators can have the following formats:
label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
example: "label=regexp:^[Oo]ther"
value=valuePattern: matches options based on their values.
example: "value=other"
id=id: matches options based on their ids.
example: "id=option1"
index=index: matches an option based on its index (offset from zero).
example: "index=2"
"""
target_elem = self._find_target(target)
tag, tvalue = self._tag_and_value(value)
select = Select(target_elem)
# the select command in the IDE does not execute javascript. So skip this command if javascript is executed
# and wait for the following click command to execute the click event which will lead you to the next page
if not target_elem.find_elements_by_css_selector('option[onclick]'):
#import pdb; pdb.set_trace()
if tag in ['label', None]:
tvalue = self._matchOptionText(target_elem, tvalue)
select.select_by_visible_text(tvalue)
elif tag == 'value':
tvalue = self._matchOptionValue(target_elem, tvalue)
select.select_by_value(tvalue)
elif tag == 'id':
option = target_elem.find_element_by_id(tvalue)
select.select_by_visible_text(option.text)
elif tag == 'index':
select.select_by_index(int(tvalue))
else:
raise UnexpectedTagNameException("Unknown option locator tag: " + tag)
示例14: select_term
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def select_term(self, term):
d = self.driver
d.get('https://loris.wlu.ca/ssb_prod/bwskflib.P_SelDefTerm')
dropdown = Select(d.find_element_by_id('term_id'))
dropdown.select_by_value(term)
d.find_elements_by_css_selector('form')[1].submit()
self.term_selected = True
示例15: batch
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import select_by_value [as 别名]
def batch(key, match_file):
workflow.webbrowser("https://www.ncbi.nlm.nih.gov/sites/batchentrez");
element1 = driver.find_element_by_name("file");
element1.send_keys(key + "/" + match_file)
element2 = Select(driver.find_element_by_name("db"));
element2.select_by_value("protein");