本文整理汇总了Python中selenium.webdriver.common.keys.Keys.SHIFT属性的典型用法代码示例。如果您正苦于以下问题:Python Keys.SHIFT属性的具体用法?Python Keys.SHIFT怎么用?Python Keys.SHIFT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类selenium.webdriver.common.keys.Keys
的用法示例。
在下文中一共展示了Keys.SHIFT属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_message
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def send_message(self, name, message):
message = self.emojify(message) # this will emojify all the emoji which is present as the text in string
search = self.browser.find_element_by_css_selector("._3FRCZ")
search.send_keys(name+Keys.ENTER) # we will send the name to the input key box
try:
send_msg = WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
(By.XPATH, "/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]")))
messages = message.split("\n")
for msg in messages:
send_msg.send_keys(msg)
send_msg.send_keys(Keys.SHIFT+Keys.ENTER)
send_msg.send_keys(Keys.ENTER)
return True
except TimeoutException:
raise TimeoutError("Your request has been timed out! Try overriding timeout!")
except NoSuchElementException:
return False
except Exception:
return False
# This method will count the no of participants for the group name provided
示例2: send_blind_message
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def send_blind_message(self, message):
try:
message = self.emojify(message)
send_msg = WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
(By.XPATH, "/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]")))
messages = message.split("\n")
for msg in messages:
send_msg.send_keys(msg)
send_msg.send_keys(Keys.SHIFT+Keys.ENTER)
send_msg.send_keys(Keys.ENTER)
return True
except NoSuchElementException:
return "Unable to Locate the element"
except Exception as e:
print(e)
return False
# This method will send you the picture
示例3: test_dbsp002_click_and_drag
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def test_dbsp002_click_and_drag(dash_duo):
app = dash.Dash(__name__)
app.layout = html.Div(
dash_bio.Speck(
id=_COMPONENT_ID,
data=_data
)
)
dash_duo.start_server(app)
dash_duo.wait_for_element('#' + _COMPONENT_ID)
speck = dash_duo.find_element('#' + _COMPONENT_ID + ' canvas')
ac = ActionChains(dash_duo.driver)
ac.move_to_element(speck).key_down(Keys.SHIFT).drag_and_drop_by_offset(
speck, -50, 100).key_up(Keys.SHIFT).perform()
dash_duo.percy_snapshot('test-speck_click_and_drag')
示例4: execute_cell
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def execute_cell(self,
cell_or_index=None,
in_console=False,
expect_error=False):
if isinstance(cell_or_index, int):
index = cell_or_index
elif isinstance(cell_or_index, WebElement):
index = self.index(cell_or_index)
else:
raise TypeError("execute_cell only accepts a WebElement or an int")
self._focus_cell(index)
if in_console:
self.current_cell.send_keys(Keys.CONTROL, Keys.SHIFT, Keys.ENTER)
self._wait_for_done(-1, expect_error)
else:
self.current_cell.send_keys(Keys.CONTROL, Keys.ENTER)
self._wait_for_done(index, expect_error)
示例5: send_message
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [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
示例6: send_unsaved_contact_message
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [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
示例7: _clear
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [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)
示例8: ctrl_shift_enter
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def ctrl_shift_enter(self, actions):
"""Useful for executing a code block"""
return actions.key_down(Keys.SHIFT).key_down(Keys.CONTROL).send_keys(Keys.ENTER) \
.key_up(Keys.SHIFT).key_up(Keys.CONTROL).perform()
示例9: enablePlayerDiagnostics
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def enablePlayerDiagnostics(self):
actions = ActionChains(self.driver)
actions.key_down(Keys.CONTROL).key_down(Keys.ALT).key_down(Keys.SHIFT).send_keys('d').perform()
示例10: test_accepts_modifiers
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def test_accepts_modifiers(self, browser):
try:
browser.link().click(Keys.SHIFT)
assert len(browser.windows()) == 2
finally:
for window in browser.windows():
if not window.is_current:
window.close()
assert len(browser.windows()) == 1
示例11: click
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def click(self, *modifiers):
"""
Clicks the element, optionally while pressing the given modifier keys.
Note that support for holding a modifier key is currently experimental, and may not work
at all.
:param modifiers: modifier keys to press while clicking
:Example: Click an element
browser.element(name='new_user_button').click()
:Example: Click an element with shift key pressed
from selenium.webdriver.common.keys import Keys
browser.element(name='new_user_button').click(Keys.SHIFT)
:Example: Click an element with several modifier keys pressed
from selenium.webdriver.common.keys import Keys
browser.element(name='new_user_button').click(Keys.SHIFT, Keys.CONTROL)
"""
def method():
if modifiers:
action = ActionChains(self.driver)
for mod in modifiers:
action.key_down(mod)
action.click(self.el)
for mod in modifiers:
action.key_up(mod)
action.perform()
else:
self.el.click()
self._element_call(method, self.wait_for_enabled)
self.browser.after_hooks.run()
示例12: _flag
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def _flag(browser):
_send_keys_to_body(browser, Keys.SHIFT, Keys.CONTROL, "f")
message = browser.find_element_by_id("statusmessage")
WebDriverWait(browser, 10).until(lambda browser: message.is_displayed())
WebDriverWait(browser, 10).until(lambda browser: not message.is_displayed())
return browser.execute_script("return $('#statusmessage').text();")
示例13: test_packages
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def test_packages(driver: selenium.webdriver, *args, **kwargs):
"""
Test that pip ,conda, and apt packages install successfully.
Args:
driver
"""
r = testutils.prep_py3_minimal_base(driver)
username, project_title = r.username, r.project_name
pip_package_construct = ("construct", "2.9.45")
conda_package_requests = ("requests", "2.22.0")
apt_package_vim = "vim-tiny"
# Install pip, conda, and apt packages
env_elts = testutils.EnvironmentElements(driver)
env_elts.open_add_packages_modal(username, project_title)
env_elts.add_pip_package(pip_package_construct[0], pip_package_construct[1])
env_elts.add_conda_package(conda_package_requests[0], conda_package_requests[1])
env_elts.add_apt_package(apt_package_vim)
env_elts.install_queued_packages()
# Open JupyterLab and create Jupyter notebook
project_control_elts = testutils.ProjectControlElements(driver)
project_control_elts.launch_devtool("JupyterLab")
project_control_elts.open_devtool_tab("JupyterLab")
jupyterlab_elts = testutils.JupyterLabElements(driver)
jupyterlab_elts.jupyter_notebook_button.wait_to_appear().click()
time.sleep(5)
logging.info("Running script to import packages and print package versions")
package_script = "import construct\nimport requests\n" \
"print(construct.__version__,requests.__version__)"
actions = ActionChains(driver)
actions.move_to_element(jupyterlab_elts.code_input.wait_to_appear()) \
.click(jupyterlab_elts.code_input.find()) \
.send_keys(package_script) \
.key_down(Keys.SHIFT).send_keys(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.CONTROL) \
.perform()
jupyterlab_elts.code_output.wait_to_appear()
# Get JupyterLab package versions
logging.info("Extracting package versions from JupyterLab")
environment_package_versions = [pip_package_construct[1], conda_package_requests[1]]
jupyterlab_package_versions = jupyterlab_elts.code_output.find().text.split(" ")
logging.info(f"Environment package version {environment_package_versions} \n "
f"JupyterLab package version {jupyterlab_package_versions}")
assert environment_package_versions == jupyterlab_package_versions,\
"Environment and JupyterLab package versions do not match"
示例14: send_emoji_message
# 需要导入模块: from selenium.webdriver.common.keys import Keys [as 别名]
# 或者: from selenium.webdriver.common.keys.Keys import SHIFT [as 别名]
def send_emoji_message(self, emoji, message):
message_field = self.browser.find_element_by_css_selector(
self.message_input_selector)
message_field.clear()
message_field.click()
emoji = EmojiAlphabet(emoji)
# Since we have only uppercase emoji alphabets
# converting the message to uppercase.
message = message.upper()
for m in message:
emoji_generator = {
'A': emoji.A,
'B': emoji.B,
'C': emoji.C,
'D': emoji.D,
'E': emoji.E,
'F': emoji.F,
'G': emoji.G,
'H': emoji.H,
'I': emoji.I,
'J': emoji.J,
'K': emoji.K,
'L': emoji.L,
'M': emoji.M,
'N': emoji.N,
'O': emoji.O,
'P': emoji.P,
'Q': emoji.Q,
'R': emoji.R,
'S': emoji.S,
'T': emoji.T,
'U': emoji.U,
'V': emoji.V,
'W': emoji.W,
'X': emoji.X,
'Y': emoji.Y,
'Z': emoji.Z,
' ': emoji.heart,
}
emoji_pieces = emoji_generator[m]()
for e in emoji_pieces:
# Todo
# Show percentage of work done/ emojis sent.
message_field.send_keys(e)
actions = ActionChains(self.browser)
actions.key_down(
Keys.SHIFT
).send_keys(Keys.ENTER).key_up(Keys.SHIFT).perform()
actions.reset_actions()
message_field.send_keys(Keys.ENTER)