本文整理汇总了Python中selenium.webdriver.support.ui.Select.deselect_all方法的典型用法代码示例。如果您正苦于以下问题:Python Select.deselect_all方法的具体用法?Python Select.deselect_all怎么用?Python Select.deselect_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.ui.Select
的用法示例。
在下文中一共展示了Select.deselect_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select_multi_items
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [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))
示例2: fset
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def fset(self, value):
if self.element.tag_name.lower() == 'file':
pass
# if self.mech_control.type == 'file':
# self.mech_control.add_file(value,
# content_type=self.content_type,
# filename=self.filename)
# select
elif self.element.tag_name.lower() == 'select':
select = Select(self.element)
if self.element.get_attribute('multiple'):
select.deselect_all()
else:
value = [value]
for opt in select.options:
v = opt.get_attribute('value')
if v in value:
value.remove(v)
if not opt.is_selected():
opt.click()
if value:
raise AttributeError('Options not found: %s' % ','.join(value))
else:
# textarea, input type=text
self.element.clear()
self.element.send_keys(value)
示例3: testDeselectAllMultiple
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def testDeselectAllMultiple(self, driver, pages):
if driver.capabilities['browserName'] == 'chrome' and int(driver.capabilities['version'].split('.')[0]) < 16:
pytest.skip("deselecting preselected values only works on chrome >= 16")
pages.load("formPage.html")
for select in [multiSelectValues1, multiSelectValues2]:
sel = Select(driver.find_element(By.NAME, select['name']))
sel.deselect_all()
assert len(sel.all_selected_options) == 0
示例4: testDeselectAllMultiple
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def testDeselectAllMultiple(self):
if self.driver.capabilities['browserName'] == 'chrome' and int(self.driver.capabilities['version'].split('.')[0]) < 16:
pytest.skip("deselecting preselected values only works on chrome >= 16")
self._loadPage("formPage")
for select in [multiSelectValues1, multiSelectValues2]:
sel = Select(self.driver.find_element(By.NAME, select['name']))
sel.deselect_all()
self.assertEqual(len(sel.all_selected_options), 0)
示例5: callback
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def callback(elements):
s = Select(elements.item)
if i is not None:
s.deselect_by_index(i)
elif value is not None:
s.deselect_by_value(value)
elif text is not None:
s.deselect_by_visible_text(text)
else:
s.deselect_all()
示例6: testSelectByVisibleTextMultiple
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def testSelectByVisibleTextMultiple(driver, pages):
pages.load("formPage.html")
for select in [multiSelectValues1, multiSelectValues2]:
sel = Select(driver.find_element(By.NAME, select['name']))
sel.deselect_all()
for x in range(len(select['values'])):
sel.select_by_visible_text(select['values'][x])
selected = sel.all_selected_options
assert len(selected) == x + 1
for j in range(len(selected)):
assert selected[j].text == select['values'][j]
示例7: select_multi_items
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def select_multi_items(browser, list, elem):
options = [unquote_variable(i.strip()) for i in list.split(",")]
select_box = find_element(browser, elem)
select = Select(select_box)
select.deselect_all()
for option in options:
try:
select.select_by_value(option)
except NoSuchElementException:
select.select_by_visible_text(option)
示例8: select_multi_items
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def select_multi_items(self, select_name):
# Ensure only the options selected are actually selected
option_names = self.multiline.split('\n')
select_box = find_field(world.browser, 'select', select_name)
select = Select(select_box)
select.deselect_all()
for option in option_names:
try:
select.select_by_value(option)
except NoSuchElementException:
select.select_by_visible_text(option)
示例9: testSelectByVisibleTextMultiple
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def testSelectByVisibleTextMultiple(self):
if self.driver.capabilities['browserName'] == 'chrome' and int(self.driver.capabilities['version'].split('.')[0]) < 16:
pytest.skip("deselecting preselected values only works on chrome >= 16")
self._loadPage("formPage")
for select in [multiSelectValues1, multiSelectValues2]:
sel = Select(self.driver.find_element(By.NAME, select['name']))
sel.deselect_all()
for x in range(len(select['values'])):
sel.select_by_visible_text(select['values'][x])
selected = sel.all_selected_options
self.assertEqual(len(selected), x+1)
for j in range(len(selected)):
self.assertEqual(selected[j].text, select['values'][j])
示例10: select_multi_items
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def select_multi_items(test, select_name, option_names):
# Ensure only the options selected are actually selected
option_names = [on.strip() for on
in option_names.split('\n') if on.strip()]
select_box = find_field(test.browser, 'select', select_name)
select = Select(select_box)
select.deselect_all()
for option in option_names:
try:
select.select_by_value(option)
except NoSuchElementException:
select.select_by_visible_text(option)
示例11: testSelectByVisibleTextMultiplePartialText
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def testSelectByVisibleTextMultiplePartialText(self):
if self.driver.capabilities['browserName'] == 'chrome' and int(self.driver.capabilities['version'].split('.')[0]) < 16:
pytest.skip("deselecting preselected values only works on chrome >= 16")
self._loadPage("formPage")
sel = Select(self.driver.find_element(By.NAME, multiSelectValues1['name']))
sel.deselect_all()
sel.select_by_visible_text("Onion gr")
self.assertEqual(sel.first_selected_option.text, multiSelectValues1['values'][3])
sel = Select(self.driver.find_element(By.NAME, multiSelectValues2['name']))
sel.deselect_all()
sel.select_by_visible_text(" ")
self.assertEqual(len(sel.all_selected_options), 4)
示例12: testSelectByVisibleTextMultiple
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def testSelectByVisibleTextMultiple(self, driver, pages):
if driver.capabilities["browserName"] == "chrome" and int(driver.capabilities["version"].split(".")[0]) < 16:
pytest.skip("deselecting preselected values only works on chrome >= 16")
pages.load("formPage.html")
for select in [multiSelectValues1, multiSelectValues2]:
sel = Select(driver.find_element(By.NAME, select["name"]))
sel.deselect_all()
for x in range(len(select["values"])):
sel.select_by_visible_text(select["values"][x])
selected = sel.all_selected_options
assert len(selected) == x + 1
for j in range(len(selected)):
assert selected[j].text == select["values"][j]
示例13: select_multi_items
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def select_multi_items(step, select_name):
with AssertContextManager(step):
# Ensure only the options selected are actually selected
option_names = step.multiline.split("\n")
select_box = find_field(world.browser, "select", select_name)
select = Select(select_box)
select.deselect_all()
for option in option_names:
try:
select.select_by_value(option)
except NoSuchElementException:
select.select_by_visible_text(option)
示例14: testSelectByIndexMultiple
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def testSelectByIndexMultiple(self, driver, pages):
if driver.capabilities['browserName'] == 'chrome' and int(driver.capabilities['version'].split('.')[0]) < 16:
pytest.skip("deselecting preselected values only works on chrome >= 16")
pages.load("formPage.html")
for select in [multiSelectValues1, multiSelectValues2]:
sel = Select(driver.find_element(By.NAME, select['name']))
sel.deselect_all()
for x in range(len(select['values'])):
sel.select_by_index(x)
selected = sel.all_selected_options
assert len(selected) == x + 1
for j in range(len(selected)):
assert selected[j].text == select['values'][j]
示例15: testDeselectByVisibleTextMultiple
# 需要导入模块: from selenium.webdriver.support.ui import Select [as 别名]
# 或者: from selenium.webdriver.support.ui.Select import deselect_all [as 别名]
def testDeselectByVisibleTextMultiple(driver, pages):
pages.load("formPage.html")
for select in [multiSelectValues1, multiSelectValues2]:
sel = Select(driver.find_element(By.NAME, select['name']))
sel.deselect_all()
sel.select_by_index(0)
sel.select_by_index(1)
sel.select_by_index(2)
sel.select_by_index(3)
sel.deselect_by_visible_text(select['values'][1])
sel.deselect_by_visible_text(select['values'][3])
selected = sel.all_selected_options
assert len(selected) == 2
assert selected[0].text == select['values'][0]
assert selected[1].text == select['values'][2]