本文整理汇总了Python中selenium.webdriver.ActionChains.key_down方法的典型用法代码示例。如果您正苦于以下问题:Python ActionChains.key_down方法的具体用法?Python ActionChains.key_down怎么用?Python ActionChains.key_down使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.ActionChains
的用法示例。
在下文中一共展示了ActionChains.key_down方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: command_ctrl_with_click
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def command_ctrl_with_click(browser, col_name, command_or_ctrl):
chains = ActionChains(browser)
element = browser.execute_script(
"return $('.ember-table-header-container .ember-table-content:contains(" + col_name + ")').parent().parent()")
if command_or_ctrl == "command":
chains.key_down(Keys.COMMAND).click(element[0]).key_up(Keys.COMMAND).perform()
elif command_or_ctrl == "control":
chains.key_down(Keys.CONTROL).click(element[0]).key_up(Keys.COMMAND).perform()
示例2: click_multiple_with_ctrl_down
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def click_multiple_with_ctrl_down(self, locator,numbers=5):
elements = self._element_find(locator, False, True)
actions = ActionChains(self._current_browser())
actions.key_down(keys.Keys.CONTROL).perform()
sampl = random.sample(elements,int(numbers))
for e in sampl:
e.click()
actions.key_up(keys.Keys.CONTROL).perform()
示例3: zoom_selection
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def zoom_selection(self):
center = self.driver.execute_script(GetScripts.getContainerCenter)
actions = ActionChains(self.driver)
actions.move_to_element_with_offset(self.element, int(center['x']), int(center['y']))
actions.key_down(Keys.SHIFT)
actions.click_and_hold()
actions.move_by_offset(300, 300)
actions.release()
actions.perform()
示例4: test_report
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def test_report(self):
self.browser.get(self.live_server_url + '/')
# Login
username = self.browser.find_element_by_id('username')
username.send_keys('Jim')
password = self.browser.find_element_by_id('password')
# Send the wrong password
password.send_keys('correcthorsebatterystaple')
# Submit the form
submit = self.browser.find_element_by_id('submit')
submit.click()
# Navigate to the sale page
img = self.browser.find_element_by_xpath(
'//div[@class="card small grey darken-3"][1]//img[@id="report-image"]')
img.click()
# Get the choose showing modal
showing = self.browser.find_element_by_xpath(
'//div[@class="col s6 center-align"][1]/button')
showing.click()
wait = WebDriverWait(self.browser, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'picker-modal')))
modal = self.browser.find_element_by_id('picker-modal')
self.assertTrue(modal.is_displayed())
occ = self.browser.find_element_by_id('showing')
occ.click()
free_text = self.browser.find_element_by_xpath('//div[@id="sale-update"]//p').text
self.assertIn('No tickets sold', free_text)
self.assertIn('No tickets reserved', free_text)
self.assertIn('80 tickets left', free_text)
# Check selling tickets adds up properly
pricing = models.InHousePricing.objects.get(id=1)
member_price = pricing.member_price
concession_price = pricing.concession_price
public_price = pricing.public_price
mat_f_price = pricing.matinee_freshers_price
mat_f_nnt_price = pricing.matinee_freshers_nnt_price
out = self.browser.find_element_by_id('out1').text
member = self.browser.find_element_by_id('member')
action = ActionChains(self.browser)
action.click(on_element=member)
action.send_keys('1')
action.key_down(Keys.CONTROL)
action.key_up(Keys.CONTROL)
action.perform()
示例5: delete_files
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def delete_files(self, file_paths):
""" Delete all the files in the list `file_paths` """
# need select all the files given in file_paths
self('files_tab').click()
for filename in file_paths:
element = self.find_file(filename)
chain = ActionChains(self.browser)
#FIXME: Mac OSX does not use CONTROL key
chain.key_down(Keys.CONTROL).click(element).key_up(Keys.CONTROL).perform()
self('files_tab').click()
self('file_menu').click()
self('delete_files_button').click()
示例6: test_remove_success
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def test_remove_success(self):
table = self.driver.find_element_by_id('dataTable')
self.create_units(table)
tr = table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(3) + ')')
actions = ActionChains(self.driver)
actions.move_to_element(tr.find_element_by_css_selector('td:nth-child(2)'))
actions.click()
actions.key_down(Keys.SHIFT)
actions.move_to_element(table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(5) + ') td:nth-child(3)'))
actions.click()
actions.key_up(Keys.SHIFT)
actions.move_to_element(table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(4) + ') td:nth-child(3)'))
actions.context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN)
actions.send_keys(Keys.RETURN)
actions.perform()
self.assertEqual(len(self.driver.find_elements_by_css_selector('.htCore tbody tr')), 3 * 2)
示例7: interact_mouse
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def interact_mouse( self ):
'''
Perform some mouse interaction in the current active browser window.
'''
canvas = self.__browser.find_element_by_tag_name( 'canvas' )
canvas_width = canvas.get_attribute('width')
canvas_height = canvas.get_attribute('height')
# move to canvas center to trigger a caption
actions = ActionChains( self.__browser )
actions.click( canvas )
actions.move_to_element_with_offset( canvas, int(canvas_width)/2, int(canvas_height)/2 )
actions.perform()
time.sleep(3)
#
# rotate, pan, zoom
#
actions = ActionChains( self.__browser )
actions.click( canvas )
# rotate
for i in range( 30 ):
actions.click_and_hold( None )
actions.move_to_element_with_offset( canvas, 10, 0 );
actions.release( canvas )
for i in range( 30 ):
actions.click_and_hold( None )
actions.move_to_element_with_offset( canvas, 0, -10 );
actions.release( canvas )
# zoom (not possible right now since the scrollwheel can't be triggered)
# pan
for i in range( 10 ):
actions.key_down( Keys.LEFT_SHIFT )
actions.click_and_hold( None )
actions.move_to_element_with_offset( canvas, 0, 10 );
actions.release( canvas )
actions.perform()
示例8: test_remove_permission
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def test_remove_permission(self):
table = self.driver.find_element_by_id('dataTable')
self.create_units(table)
self.driver.authorize(username=self.guest.email, password='qwerty')
self.driver.open_url(reverse('units:list', kwargs={'lab_pk': unicode(self.lab.pk)}))
table = self.driver.find_element_by_id('dataTable')
tr = table.find_element_by_css_selector('.htCore tbody tr:nth-child(1)')
actions = ActionChains(self.driver)
actions.move_to_element(tr.find_element_by_css_selector('td:nth-child(2)'))
actions.click()
actions.key_down(Keys.SHIFT)
actions.move_to_element(table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(5) + ') td:nth-child(3)'))
actions.click()
actions.key_up(Keys.SHIFT)
actions.move_to_element(table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(4) + ') td:nth-child(3)'))
actions.context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN)
actions.send_keys(Keys.RETURN)
actions.perform()
self.assertTrue(self.driver.is_element_present('.alert-danger'))
self.assertEqual(self.driver.find_element_by_css_selector('.messages').text, 'PERMISSION DENIED')
示例9: delete_files
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def delete_files(self, file_paths, confirm=True):
""" Delete all the files in the list `file_paths` """
# need select all the files given in file_paths
self('files_tab').click()
for filename in file_paths:
element = self.find_file(filename)
chain = ActionChains(self.browser)
#Mac OSX does not use CONTROL key
if sys.platform == 'darwin':
chain.key_down(Keys.SHIFT).click(element).key_up(Keys.SHIFT).perform()
else:
chain.key_down(Keys.CONTROL).click(element).key_up(Keys.CONTROL).perform()
self('files_tab').click()
self('file_menu').click()
self('delete_files_button').click()
page = ConfirmationPage(self)
if confirm:
page.click_ok()
else:
page.click_cancel()
示例10: trigger_keystrokes
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def trigger_keystrokes(browser, *keys):
""" Send the keys in sequence to the browser.
Handles following key combinations
1. with modifiers eg. 'control-alt-a', 'shift-c'
2. just modifiers eg. 'alt', 'esc'
3. non-modifiers eg. 'abc'
Modifiers : http://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html
"""
for each_key_combination in keys:
keys = each_key_combination.split('-')
if len(keys) > 1: # key has modifiers eg. control, alt, shift
modifiers_keys = [getattr(Keys, x.upper()) for x in keys[:-1]]
ac = ActionChains(browser)
for i in modifiers_keys: ac = ac.key_down(i)
ac.send_keys(keys[-1])
for i in modifiers_keys[::-1]: ac = ac.key_up(i)
ac.perform()
else: # single key stroke. Check if modifier eg. "up"
browser.send_keys(getattr(Keys, keys[0].upper(), keys[0]))
示例11: clickAndClearWindowTextView
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def clickAndClearWindowTextView(window):
print "clickAndClearWindowTextView: " + window.get_attribute("AXTitle")
action = ActionChains(driver).click(window)
action.key_down(Keys.COMMAND).send_keys("a").key_up(Keys.COMMAND).send_keys(Keys.BACKSPACE).perform()
textView = utilities.findElementByXPath(driver, "/AXApplication/AXWindow[0]/AXScrollArea[0]/AXTextArea[@AXIdentifier='First Text View']")
return textView
示例12: BeautifulSoup
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
elements = driver.find_elements_by_class_name("db10ub")
html_source = driver.page_source
soup = BeautifulSoup(html_source)
table = soup.find('table', cellpadding='3')
while y < len(elements):
if soup.findAll('a',href=True):
for item in table:
y = str(y)
element = driver.find_element_by_xpath('//table[2]/tbody/tr[4]/td/div/table/tbody/tr['+y+']/td[2]/font/a')
y = int(y)
element.click()
y+=1
print y
html_source = driver.page_source
soup = BeautifulSoup(html_source)
if soup.find('table', id='tabTwo'):
element = driver.find_element_by_xpath("//tr[2]/td[6]/font/a")
element.click()
sleep(5)
win = driver.window_handles
driver.switch_to_window(win[1])
AC.key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
sleep(1)
AC.send_keys(Keys.ENTER)
print "Saved"
driver.switch_to_window(win[0])
driver.back()
z+=1
driver.back()
示例13: interact_keyboard
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
def interact_keyboard( self ):
'''
Perform some keyboard interaction in the current active browser window.
'''
canvas = self.__browser.find_element_by_tag_name( 'canvas' )
actions = ActionChains( self.__browser )
actions.click( canvas )
#
# keyboard events
#
# rotate
for i in range( 30 ):
actions.send_keys( Keys.ARROW_RIGHT )
for i in range( 30 ):
actions.send_keys( Keys.ARROW_UP )
for i in range( 30 ):
actions.send_keys( Keys.ARROW_LEFT )
for i in range( 30 ):
actions.send_keys( Keys.ARROW_DOWN )
# zoom
for i in range( 50 ):
actions.key_down( Keys.LEFT_ALT )
actions.send_keys( Keys.ARROW_LEFT )
for i in range( 25 ):
actions.key_down( Keys.LEFT_ALT )
actions.send_keys( Keys.ARROW_RIGHT )
# pan
actions.key_down( Keys.LEFT_SHIFT )
actions.send_keys( Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, Keys.ARROW_RIGHT )
actions.key_down( Keys.LEFT_SHIFT )
actions.send_keys( Keys.ARROW_LEFT, Keys.ARROW_LEFT, Keys.ARROW_LEFT )
actions.key_down( Keys.LEFT_SHIFT )
actions.send_keys( Keys.ARROW_UP, Keys.ARROW_UP, Keys.ARROW_UP )
actions.key_down( Keys.LEFT_SHIFT )
actions.send_keys( Keys.ARROW_DOWN, Keys.ARROW_DOWN )
actions.perform()
示例14: runTests
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import key_down [as 别名]
#.........这里部分代码省略.........
#browser.switch_to_frame( browser.find_elements_by_tag_name( "iframe" )[0] )
# wait until loading fully completed
timer = 0
while not browser.execute_script( 'return test_renderer.loadingCompleted' ) and timer < 5:
time.sleep( 1 ) # loading did not complete yet
timer += 1
time.sleep( 1 )
# perform interaction tests, if we are using chrome
if browserString == 'chrome':
canvas = browser.find_element_by_tag_name( 'canvas' )
actions = ActionChains( browser )
actions.click( canvas )
#
# keyboard events
#
# rotate
for i in range( 30 ):
actions.send_keys( Keys.ARROW_RIGHT )
for i in range( 30 ):
actions.send_keys( Keys.ARROW_UP )
for i in range( 30 ):
actions.send_keys( Keys.ARROW_LEFT )
for i in range( 30 ):
actions.send_keys( Keys.ARROW_DOWN )
# zoom
for i in range( 50 ):
actions.key_down( Keys.LEFT_ALT )
actions.send_keys( Keys.ARROW_LEFT )
for i in range( 25 ):
actions.key_down( Keys.LEFT_ALT )
actions.send_keys( Keys.ARROW_RIGHT )
# pan
actions.key_down( Keys.LEFT_SHIFT )
actions.send_keys( Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, Keys.ARROW_RIGHT )
actions.key_down( Keys.LEFT_SHIFT )
actions.send_keys( Keys.ARROW_LEFT, Keys.ARROW_LEFT, Keys.ARROW_LEFT )
actions.key_down( Keys.LEFT_SHIFT )
actions.send_keys( Keys.ARROW_UP, Keys.ARROW_UP, Keys.ARROW_UP )
actions.key_down( Keys.LEFT_SHIFT )
actions.send_keys( Keys.ARROW_DOWN, Keys.ARROW_DOWN )
#
# mouse
#
actions.click( canvas )
# rotate
for i in range( 30 ):
actions.click_and_hold( None )
actions.move_to_element_with_offset( canvas, 10, 0 );
actions.release( canvas )
for i in range( 30 ):
actions.click_and_hold( None )
actions.move_to_element_with_offset( canvas, 0, -10 );
actions.release( canvas )
# zoom