本文整理汇总了Python中selenium.webdriver.common.action_chains.ActionChains.key_down方法的典型用法代码示例。如果您正苦于以下问题:Python ActionChains.key_down方法的具体用法?Python ActionChains.key_down怎么用?Python ActionChains.key_down使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.common.action_chains.ActionChains
的用法示例。
在下文中一共展示了ActionChains.key_down方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FillPasswordInto
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def FillPasswordInto(self, selector):
"""Ensures that the selected element's value is the saved password.
Depending on self.autofill_expectation, this either checks that the
element already has the password autofilled, or checks that the value
is empty and replaces it with the password.
Args:
selector: The CSS selector for the filled element.
Raises:
Exception: An exception is raised if the element's value is different
from the expectation.
"""
logging.log(SCRIPT_DEBUG, "action: FillPasswordInto %s" % selector)
password_element = self.WaitUntilDisplayed(selector)
# Chrome protects the password inputs and doesn't fill them until
# the user interacts with the page. To be sure that such thing has
# happened we perform |Keys.CONTROL| keypress.
action_chains = ActionChains(self.driver)
action_chains.key_down(Keys.CONTROL).key_up(Keys.CONTROL).perform()
self.Wait(2) # TODO(vabr): Detect when autofill finished.
if self.autofill_expectation == WebsiteTest.AUTOFILLED:
if password_element.get_attribute("value") != self.password:
raise Exception("Error: autofilled password is different from the saved"
" one on website: %s" % self.name)
elif self.autofill_expectation == WebsiteTest.NOT_AUTOFILLED:
if password_element.get_attribute("value"):
raise Exception("Error: password value unexpectedly not empty on"
"website: %s" % self.name)
password_element.send_keys(self.password)
示例2: testClipboardShortcut
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def testClipboardShortcut(self):
"""
@status confirm the shortcut keys(CTRL + ALT + k) resets the clipboard input box
"""
actions = ActionChains(self.driver)
#search for the term tail
self.performSearch(term="tail")
result = self.driver.find_element_by_id("termResultList").find_element_by_css_selector("mark")
result.click()
wait.forAngular(self.driver)
#clear all items in the clipboard
clear = self.driver.find_element_by_id("clipboardFunctions").find_element_by_id("clipboardClear")
clear.click()
#Add 18 into the add to clipboard field
clipbox = self.driver.find_element_by_id("clipboardInput")
clipbox.send_keys("18")
clipbox.send_keys(Keys.RETURN)
clipdata = self.driver.find_element_by_id("emapClipBoardContent").find_element_by_id("clipboard")
items = clipdata.find_elements_by_css_selector("li")
searchTreeItems = iterate.getTextAsList(items)
#assert that TS18 tail is displayed in the clipboard
self.assertEqual(["TS18; tail"], searchTreeItems)
#clear the clipboard using the shortcut keys
actions.key_down(Keys.CONTROL).key_down(Keys.ALT).send_keys('k').key_up(Keys.CONTROL).key_up(Keys.ALT).perform()
time.sleep(5)
clipdata = self.driver.find_element_by_id("emapClipBoardContent")
items = clipdata.find_elements_by_css_selector("li")
searchTreeItems = iterate.getTextAsList(items)
#Assert that the clipboard is empty
self.assertEqual([], searchTreeItems)
示例3: _Apply
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def _Apply(self, driver, test):
expected_value = test.profile_data(self._expected_type)
if expected_value != '':
if self._trigger_character is None:
trigger_character = expected_value[0]
else:
trigger_character = self._trigger_character
else:
test.expect_expression(
overall_type,
'Failure: Cannot trigger autofill, field_type \'%s\' '
'does not have an expected value' % self._expected_type)
return
locator = self._element_selector.tuple()
wt = WebDriverWait(driver, 15) # seconds
element = wt.until(EC.presence_of_element_located(locator))
ActionChains(driver).move_to_element(element).perform()
wt = WebDriverWait(driver, 10) # seconds
element = wt.until(EC.element_to_be_clickable(locator))
ActionChains(driver).click(element).perform()
time.sleep(1)
actions = ActionChains(driver)
actions.send_keys(trigger_character)
actions.perform()
time.sleep(0.5)
actions = ActionChains(driver)
actions.key_down(Keys.ARROW_DOWN)
actions.key_down(Keys.ENTER)
actions.perform()
time.sleep(1)
return True
示例4: shop_button_second_slide_click
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def shop_button_second_slide_click(self):
self._driver.find_element(*HomePage.second_products_slide).click()
action = ActionChains(self._driver)
action.key_down(Keys.SHIFT)
time.sleep(2)
action.click(self._driver.find_element(*HomePage.shop_button_second_slide))
action.key_up(Keys.SHIFT)
action.perform()
示例5: open_link_in_new_tab
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def open_link_in_new_tab(self, elem):
CONTROL_KEY = get_control_key()
actions = ActionChains(self.driver)
actions.move_to_element(elem)
actions.key_down(CONTROL_KEY)
actions.click(elem)
actions.key_up(CONTROL_KEY)
actions.perform()
示例6: paste_values
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def paste_values(driver, el=None):
actions = ActionChains(driver)
if el:
actions.move_to_element(el)
actions.key_down(Keys.SHIFT)
actions.send_keys(Keys.INSERT)
actions.key_up(Keys.SHIFT)
#actions.send_keys(Keys.CONTROL, 'v')
actions.perform()
示例7: twitter_social_info
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def twitter_social_info(self):
# Create an Instance from ActionChains
action = ActionChains(self._driver)
# Find the Twitter link in the home page then click on it
self._driver.find_element(*HomePage.twitter_link)
# The below steps are used to open the facebook_link in a new window instead of a new tab
action.key_down(Keys.SHIFT)
action.click(self._driver.find_element(*HomePage.twitter_link))
action.key_up(Keys.SHIFT)
action.perform()
示例8: drag_element_at_position
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def drag_element_at_position(self, element, x, y, dx, dy, mod=None):
actions = ActionChains(self._driver)
if mod:
actions.key_down(mod)
actions.move_to_element_with_offset(element, x, y)
actions.click_and_hold()
actions.move_by_offset(dx, dy)
actions.release()
if mod:
actions.key_up(mod)
actions.perform()
示例9: key_down
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def key_down(self, locator, keySequence):
"""Sends a key press only, without releasing it.
Should only be used with modifier keys (Control, Alt and Shift).
:Args:
- key: The modifier key to send. Values are defined in Keys class.
- target: The element to send keys.
If None, sends a key to current focused element.
"""
el = self.driver.find_element(self.getBy(locator), self.getValue(locator))
actionChains = ActionChains(self.driver)
actionChains.key_down(keySequence, el).perform()
示例10: _click_with_modifier
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def _click_with_modifier(self, locator, tag, modifier):
self.info("Clicking %s '%s' with %s." % (tag if tag[0] else 'element', locator, modifier))
modifier = self.parse_modifier(modifier)
action = ActionChains(self.driver)
for item in modifier:
action.key_down(item)
element = self.find_element(locator, tag=tag[0], required=False)
if not element:
element = self.find_element(locator, tag=tag[1])
action.click(element)
for item in modifier:
action.key_up(item)
action.perform()
示例11: perform_box_selection
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def perform_box_selection(selenium, start, end, hold_shift=False):
canvas = selenium.find_element_by_tag_name('canvas')
wait_for_canvas_resize(canvas, selenium)
actions = ActionChains(selenium)
if hold_shift:
actions.key_down(Keys.LEFT_SHIFT)
actions.move_to_element_with_offset(canvas, *start)
actions.click_and_hold()
actions.move_by_offset(*end)
actions.release()
if hold_shift:
actions.key_up(Keys.LEFT_SHIFT)
actions.perform()
示例12: _select_items_from_file_list_upon_cond
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def _select_items_from_file_list_upon_cond(driver, item_list, keys,
cond=_is_file_selected,
all_items=None):
all_items = all_items if all_items else _get_items_from_file_list(driver)
actions = ActionChains(driver)
for key in keys:
actions.key_down(key)
for item_name in parse_seq(item_list):
item = all_items.get(item_name)
if cond(item):
actions.click(item[0])
for key in keys:
actions.key_up(key)
actions.perform()
示例13: copy_table_rows
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def copy_table_rows(driver, rows):
actions = ActionChains(driver)
row = get_table_row(driver, rows[0])
actions.move_to_element(row)
actions.click()
actions.key_down(Keys.SHIFT)
for r in rows[1:]:
row = get_table_row(driver, r)
actions.move_to_element(row)
actions.click()
actions.key_up(Keys.SHIFT)
actions.key_down(Keys.CONTROL)
actions.send_keys(Keys.INSERT)
actions.key_up(Keys.CONTROL)
#actions.send_keys(Keys.CONTROL, 'c')
actions.perform()
示例14: product_image_click
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def product_image_click(self):
if self._driver.find_element(*NegativeCases.pick_me_button).is_displayed():
self._driver.find_element(*NegativeCases.product_image).click()
if not (self._driver.find_element(*NegativeCases.pick_me_button).is_displayed()):
action = ActionChains(self._driver)
action.key_down(Keys.ESCAPE)
action.key_up(Keys.ESCAPE)
action.perform()
if self._driver.find_element(*NegativeCases.pick_me_button).is_displayed():
return True
else:
return False
else:
return False
else:
return False
示例15: FillPasswordInto
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import key_down [as 别名]
def FillPasswordInto(self, selector):
"""If the testing mode is the Autofilled mode, compares the website
password to the DOM state.
If the testing mode is the NotAutofilled mode, checks that the DOM state
is empty.
Then, fills the input with the Website password.
Args:
selector: The password input CSS selector.
Raises:
Exception: An exception is raised if the DOM value of the password is
different than the one we expected.
"""
logging.info("action: FillPasswordInto %s" % selector)
self.WaitUntilDisplayed(selector)
password_element = self.driver.find_element_by_css_selector(selector)
# Chrome protects the password inputs and doesn't fill them until
# the user interacts with the page. To be sure that such thing has
# happened we perform |Keys.CONTROL| keypress.
action_chains = ActionChains(self.driver)
action_chains.key_down(Keys.CONTROL).key_up(Keys.CONTROL).perform()
if self.mode == self.Mode.AUTOFILLED:
autofilled_password = password_element.get_attribute("value")
if autofilled_password != self.password:
raise Exception("Error: autofilled password is different from the one "
"we just saved for the following website : %s p1: %s "
"p2:%s \n" % (self.name,
password_element.get_attribute("value"),
self.password))
elif self.mode == self.Mode.NOT_AUTOFILLED:
autofilled_password = password_element.get_attribute("value")
if autofilled_password:
raise Exception("Error: password is autofilled when it shouldn't be "
"for the following website : %s \n"
% self.name)
password_element.send_keys(self.password)