本文整理汇总了Python中selenium.webdriver.common.keys.Keys.BACKSPACE属性的典型用法代码示例。如果您正苦于以下问题:Python Keys.BACKSPACE属性的具体用法?Python Keys.BACKSPACE怎么用?Python Keys.BACKSPACE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类selenium.webdriver.common.keys.Keys
的用法示例。
在下文中一共展示了Keys.BACKSPACE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_information
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def add_information(driver, link, title_):
# 点击模板
driver.find_element_by_xpath(r'//*[@class="normal-title-wrp"]/div/p').click()
driver.find_element_by_class_name(r'template-list-small-item').click()
# driver.find_element_by_xpath(
# r'//*[@id="app"]/div[3]/div[2]/div[3]/div[1]/div[1]/div/div[2]/div[1]').click()
# 输入转载来源
input_o = driver.find_element_by_xpath(
'//*[@class="upload-v2-container"]/div[2]/div[3]/div[1]/div[4]/div[3]/div/div/input')
input_o.send_keys(link)
# 选择分区
# driver.find_element_by_xpath(r'//*[@id="item"]/div/div[2]/div[3]/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div[3]/div').click()
# driver.find_element_by_xpath(r'//*[@id="item"]/div/div[2]/div[3]/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div[3]/div[2]/div[6]').click()
# 稿件标题
title = driver.find_element_by_xpath(
'//*[@class="upload-v2-container"]/div[2]/div[3]/div[1]/div[8]/div[2]/div/div/input')
title.send_keys(Keys.CONTROL + 'a')
title.send_keys(Keys.BACKSPACE)
title.send_keys(title_)
# js = "var q=document.getElementsByClassName('content-tag-list')[0].scrollIntoView();"
# driver.execute_script(js)
# time.sleep(3)
# 输入相关游戏
# driver.save_screenshot('bin/err.png')
# print('截图')
# text_1 = driver.find_element_by_xpath(
# '//*[@id="item"]/div/div[2]/div[3]/div[2]/div[2]/div[1]/div[5]/div/div/div[1]/div[2]/div/div/input')
# text_1.send_keys('星际争霸2')
# 简介
text_2 = driver.find_element_by_xpath(
'//*[@class="upload-v2-container"]/div[2]/div[3]/div[1]/div[12]/div[2]/div/textarea')
text_2.send_keys('职业选手直播第一视角录像。这个自动录制上传的小程序开源在Github:'
'http://t.cn/RgapTpf(或者在Github搜索ForgQi)交流群:837362626'
'\n顺便推广一下自己的网站http://web-form.me/')
示例2: backspace
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def backspace(self):
elem = self.__get_element(self.k, self.v)
elem.send_keys(Keys.BACKSPACE)
示例3: send_message
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def send_message(target):
global message, wait, browser
try:
x_arg = '//span[contains(@title,' + target + ')]'
ct = 0
while ct != 10:
try:
group_title = wait.until(EC.presence_of_element_located((By.XPATH, x_arg)))
group_title.click()
break
except:
ct += 1
time.sleep(3)
input_box = browser.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
for ch in message:
if ch == "\n":
ActionChains(browser).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.BACKSPACE).perform()
else:
input_box.send_keys(ch)
input_box.send_keys(Keys.ENTER)
print("Message sent successfuly")
time.sleep(1)
except NoSuchElementException:
return
示例4: send_unsaved_contact_message
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def send_unsaved_contact_message():
global message
try:
time.sleep(7)
input_box = browser.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
for ch in message:
if ch == "\n":
ActionChains(browser).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.BACKSPACE).perform()
else:
input_box.send_keys(ch)
input_box.send_keys(Keys.ENTER)
print("Message sent successfuly")
except NoSuchElementException:
print("Failed to send message")
return
示例5: _clear
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def _clear(self, element):
"""Clear the field, using any means necessary
This is surprisingly hard to do with a generic solution. Some
methods work for some components and/or on some browsers but
not others. Therefore, several techniques are employed.
"""
element.clear()
self.selenium.driver.execute_script("arguments[0].value = '';", element)
# Select all and delete just in case the element didn't get cleared
element.send_keys(Keys.HOME + Keys.SHIFT + Keys.END)
element.send_keys(Keys.BACKSPACE)
if element.get_attribute("value"):
# Give the UI a chance to settle down. The sleep appears
# necessary. Without it, this keyword sometimes fails to work
# properly. With it, I was able to run 700+ tests without a single
# failure.
time.sleep(0.25)
# Even after all that, some elements refuse to be cleared out.
# I'm looking at you, currency fields on Firefox.
if element.get_attribute("value"):
self._force_clear(element)
示例6: _force_clear
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def _force_clear(self, element):
"""Use brute-force to clear an element
This moves the cursor to the end of the input field and
then issues a series of backspace keys to delete the data
in the field.
"""
value = element.get_attribute("value")
actions = ActionChains(self.selenium.driver)
actions.move_to_element(element).click().send_keys(Keys.END)
for character in value:
actions.send_keys(Keys.BACKSPACE)
actions.perform()
示例7: backspace
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def backspace(self):
self.elem.send_keys(Keys.BACKSPACE)
示例8: add_sensitive_file
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def add_sensitive_file(self, username, project_title, sensitive_file_path, sensitive_file_destination):
"""Add a sensitive file."""
logging.info("Adding sensitive file")
self.driver.get(os.environ['GIGANTUM_HOST'] + f'/projects/{username}/{project_title}/environment')
self.driver.execute_script("window.scrollBy(0, 600);")
self.advanced_configuration_button.wait_to_appear().click()
self.driver.execute_script("window.scrollBy(0, 600);")
self.add_sensitive_file_manager_upload.find().send_keys(sensitive_file_path)
self.add_sensitive_file_location.click()
self.add_sensitive_file_location.find().send_keys(Keys.BACKSPACE)
self.add_sensitive_file_location.find().send_keys(Keys.BACKSPACE)
self.add_sensitive_file_location.find().send_keys(sensitive_file_destination)
self.sensitive_file_save_button.click()
self.sensitive_file_table.wait_to_appear()
示例9: set
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def set(self, value, clear=None):
tag_name = self.tag_name
type_attr = self["type"]
if tag_name == "input" and type_attr == "radio":
self.click()
elif tag_name == "input" and type_attr == "checkbox":
current = self.native.get_attribute("checked") == "true"
if current ^ value:
self.click()
elif tag_name == "textarea" or tag_name == "input":
if self.readonly:
raise ReadOnlyElementError()
if clear == "backspace":
# Clear field by sending the correct number of backspace keys.
backspaces = [Keys.BACKSPACE] * len(self.value)
self.native.send_keys(*([Keys.END] + backspaces + [value]))
else:
# Clear field by JavaScript assignment of the value property.
self.driver.browser.execute_script("arguments[0].value = ''", self.native)
self.native.send_keys(value)
elif self["isContentEditable"]:
self.native.click()
script = """
var range = document.createRange();
var sel = window.getSelection();
range.selectNodeContents(arguments[0]);
sel.removeAllRanges();
sel.addRange(range);
"""
self.driver.browser.execute_script(script, self.native)
self.native.send_keys(value)
示例10: test_input_cast_and_ignore_empty
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def test_input_cast_and_ignore_empty(driver, driver_wait, display):
# ignore empty since that's an invalid float
change_occured = Event()
inp = idom.Input("number", 1, {"id": "inp"}, cast=float, ignore_empty=True)
@inp.events.on("change")
async def on_change(event):
change_occured.set()
display(inp)
client_inp = driver.find_element_by_id("inp")
assert client_inp.get_attribute("value") == "1"
send_keys(client_inp, Keys.BACKSPACE)
time.sleep(0.1) # waiting and deleting again seems to decrease flakiness
send_keys(client_inp, Keys.BACKSPACE)
assert change_occured.wait(timeout=3.0)
assert client_inp.get_attribute("value") == ""
# change ignored server side
assert inp.value == 1
send_keys(client_inp, "2")
driver_wait.until(lambda drv: inp.value == 2)
示例11: test_performs_key_combinations
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def test_performs_key_combinations(self, browser):
receiver = browser.text_field(id='receiver')
receiver.send_keys('foo')
receiver.send_keys(MODIFIER + 'a' + Keys.NULL)
receiver.send_keys(Keys.BACKSPACE)
assert receiver.value == ''
assert len(browser.element(id='output').ps()) == 6
示例12: test_supports_combination_of_strings_and_arrays
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def test_supports_combination_of_strings_and_arrays(self, browser):
receiver = browser.text_field(id='receiver')
receiver.send_keys('foo', [MODIFIER, 'a'], Keys.BACKSPACE)
assert receiver.value == ''
assert len(browser.element(id='output').ps()) == 6
示例13: test_dbsv003_search
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import BACKSPACE [as 别名]
def test_dbsv003_search(dash_duo):
app = dash.Dash(__name__)
app.layout = html.Div(user_interactions_layout(
dash_bio.SequenceViewer(
id=_COMPONENT_ID,
sequence=_data
)
))
user_interactions_callback(
app,
dash_duo,
component_id=_COMPONENT_ID,
prop_name='subpartSelected'
)
output_div = dash_duo.find_element('#interaction-results')
search_input = dash_duo.find_element('input.inputSearchSeq')
search_input.click()
search_input.send_keys('lal')
dash_duo.wait_for_element('span.stringsSelected')
assert output_div.get_attribute('innerHTML') == json.dumps([
{'start': 80, 'end': 82, 'sequence': 'LAL'},
{'start': 14, 'end': 16, 'sequence': 'LAL'},
{'start': 11, 'end': 13, 'sequence': 'LAL'}
])
# search for something else
search_input.click()
for i in range(len('lal')):
search_input.send_keys(Keys.BACKSPACE)
search_input.send_keys('SL')
WebDriverWait(dash_duo.driver, 1).until(
lambda _:
output_div.get_attribute('innerHTML') == json.dumps([
{"start": 101, "end": 102, "sequence": "SL"},
{"start": 85, "end": 86, "sequence": "SL"},
{"start": 76, "end": 77, "sequence": "SL"}
])
)
highlighted_sections = dash_duo.find_elements('span.stringsSelected')
assert len(highlighted_sections) == 3
for section in highlighted_sections:
assert section.get_attribute('innerHTML') == 'SL'