本文整理汇总了Python中selenium.webdriver.ActionChains方法的典型用法代码示例。如果您正苦于以下问题:Python webdriver.ActionChains方法的具体用法?Python webdriver.ActionChains怎么用?Python webdriver.ActionChains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver
的用法示例。
在下文中一共展示了webdriver.ActionChains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_08_wrong_account
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def test_08_wrong_account(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/reconcile')
src = selenium.find_element_by_id('ofx-1-OFXT4')
tgt = selenium.find_element_by_id(
'trans-4').find_element_by_class_name('reconcile-drop-target')
# get the innerHTML of both columns
trans_div = selenium.find_element_by_id('trans-panel').get_attribute(
'innerHTML')
ofxtrans_div = selenium.find_element_by_id('ofx-panel').get_attribute(
'innerHTML')
# drag and drop
chain = ActionChains(selenium)
chain.drag_and_drop(src, tgt).perform()
# sleep a bit for the drag to stop
sleep(1)
# ensure both columns are still the same
assert selenium.find_element_by_id('trans-panel').get_attribute(
'innerHTML') == trans_div
assert selenium.find_element_by_id('ofx-panel').get_attribute(
'innerHTML') == ofxtrans_div
# ensure reconciled JS var is still the same
assert self.get_reconciled(selenium) == {}
示例2: test_09_wrong_amount
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def test_09_wrong_amount(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/reconcile')
src = selenium.find_element_by_id('ofx-1-OFXT4')
tgt = selenium.find_element_by_id(
'trans-1').find_element_by_class_name('reconcile-drop-target')
# get the innerHTML of both columns
trans_div = selenium.find_element_by_id('trans-panel').get_attribute(
'innerHTML')
ofxtrans_div = selenium.find_element_by_id('ofx-panel').get_attribute(
'innerHTML')
# drag and drop
chain = ActionChains(selenium)
chain.drag_and_drop(src, tgt).perform()
# sleep a bit for the drag to stop
sleep(1)
# ensure both columns are still the same
assert selenium.find_element_by_id('trans-panel').get_attribute(
'innerHTML') == trans_div
assert selenium.find_element_by_id('ofx-panel').get_attribute(
'innerHTML') == ofxtrans_div
# ensure reconciled JS var is still the same
assert self.get_reconciled(selenium) == {}
示例3: test_10_wrong_acct_and_amount
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def test_10_wrong_acct_and_amount(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/reconcile')
src = selenium.find_element_by_id('ofx-1-OFXT4')
tgt = selenium.find_element_by_id(
'trans-3').find_element_by_class_name('reconcile-drop-target')
# get the innerHTML of both columns
trans_div = selenium.find_element_by_id('trans-panel').get_attribute(
'innerHTML')
ofxtrans_div = selenium.find_element_by_id('ofx-panel').get_attribute(
'innerHTML')
# drag and drop
chain = ActionChains(selenium)
chain.drag_and_drop(src, tgt).perform()
# sleep a bit for the drag to stop
sleep(1)
# ensure both columns are still the same
assert selenium.find_element_by_id('trans-panel').get_attribute(
'innerHTML') == trans_div
assert selenium.find_element_by_id('ofx-panel').get_attribute(
'innerHTML') == ofxtrans_div
# ensure reconciled JS var is still the same
assert self.get_reconciled(selenium) == {}
示例4: Set
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def Set(self, value):
logger.step_normal("Element [%s]: Set [%s]." % (self.__name__, value))
value = str(value)
self.__wait()
elements = Browser.RunningBrowser.find_elements(self.by, self.value)
if elements[self.index].tag_name == "select" or elements[self.index].tag_name == "ul":
self.Select(value)
else:
elements[self.index].clear()
elements[self.index].send_keys(value)
"""
elements[self.index].clear()
action = webdriver.ActionChains(Browser.RunningBrowser)
action.send_keys_to_element(elements[self.index], value)
action.perform()
"""
示例5: start_drag
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def start_drag(driver, distance):
# 被妖怪吃掉了
# knob = WAIT.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#gc-box > div > div.gt_slider > div.gt_slider_knob.gt_show")))
# ActionChains(driver).click_and_hold(knob).perform()
# ActionChains(driver).move_by_offset(xoffset=distance, yoffset=0.1).perform()
# time.sleep(0.5)
# ActionChains(driver).release(knob).perform()
# 被妖怪吃掉了
# ActionChains(driver).drag_and_drop_by_offset(knob, distance-10, 0).perform()
knob = WAIT.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#gc-box > div > div.gt_slider > div.gt_slider_knob.gt_show")))
result = get_path(distance)
ActionChains(driver).click_and_hold(knob).perform()
for x in result:
ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
time.sleep(0.5)
ActionChains(driver).release(knob).perform()
示例6: move_to
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def move_to(self, selector, click=False):
'''
Move to the element matched by selector or passed as argument.
Parameters
----------
selector: str
Any valid CSS selector
click: bool
Whether or not to click the element after hovering
defaults to False
'''
try:
elem = self.get_element(selector)
action = webdriver.ActionChains(self.browser)
action.move_to_element(elem)
if click:
action.click(elem)
action.perform()
except WebDriverException:
print("move_to isn't supported with this browser driver.")
示例7: drag_and_drop
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def drag_and_drop(self, from_selector, to_selector):
'''
Drags an element into another.
Parameters
----------
from_selector: str
A CSS selector to search for. This can be any valid CSS selector.
Element to be dragged.
to_selector: str
A CSS selector to search for. This can be any valid CSS selector.
Target element to be dragged into.
'''
from_element = self.get_element(from_selector)
to_element = self.get_element(to_selector)
ActionChains(self.browser).drag_and_drop(from_element, to_element).perform()
示例8: _drag_and_drop
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def _drag_and_drop(self, source, **kwargs):
"""Send values to a particular element,
simulates typing into a element
:Arguments:
1. source = a valid WebElement
2. target = a valid WebElement
"""
status = True
print_info("Simulate a drag and drop")
try:
browser_instance = kwargs.get('browser')
target = self._get_element(browser_instance,
kwargs.get('target_locator'))
if source is not None and target is not None:
ActionChains(browser_instance).drag_and_drop(source,
target).perform()
except Exception as e:
print_error("An Exception Occurred {}".format(e))
status = False
return status
示例9: _drag_and_drop_by_offset
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def _drag_and_drop_by_offset(self, source, **kwargs):
"""Holds down the left mouse button on the source element,
then moves to the target offset and releases the mouse button
:Arguments:
1. source = a valid WebElement
2. xoffset = X offset to move to
3. yoffset = Y offset to move to
"""
status = True
print_info("drag and drop an element with offset")
try:
xoffset = kwargs.get('xoffset')
yoffset = kwargs.get('yoffset')
browser_instance = kwargs.get('browser')
actions = ActionChains(browser_instance)
actions.drag_and_drop_by_offset(source, xoffset, yoffset).perform()
except NoSuchElementException as e:
print_error("NoSuchElementException occurred")
status = False
except Exception as e:
print_error("An Exception Occurred {}".format(e))
status = False
return status
示例10: trigger_keystrokes
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [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: process_ad_divs
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def process_ad_divs(ad_divs, ad_count, driver, dirname, ad_limit, wait=0):
# Add whitespace to bottom to allow scrolling to bottom row
window_height = driver.execute_script('return window.innerHeight')
driver.execute_script("arguments[0].setAttribute('style', 'margin-bottom:{}px;')".format(window_height),
ad_divs[-1])
processed_add_divs = set()
for ad_div in ad_divs:
if ad_count > 0:
sleep(wait)
ad_count += 1
print('Ad {}'.format(ad_count))
screenshot(ad_div, ad_count, dirname, driver)
# Click Ad Performance
ad_div.find_element_by_partial_link_text('See Ad Performance').click()
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
processed_add_divs.add(ad_div)
if ad_limit == ad_count:
break
return processed_add_divs
示例12: hover
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def hover(self) -> Element:
actions: ActionChains = ActionChains(self.config.driver)
self.wait.command('hover', lambda element: actions.move_to_element(element()).perform())
return self
# todo: should we reflect queries as self methods? or not...
# pros: faster to query element attributes
# cons: queries are not test oriented. test is steps + asserts
# so queries will be used only occasionally, then why to make a heap from Element?
# hence, occasionally it's enough to have them called as
# query.outer_html(element) # non-waiting version
# or
# element.get(query.outer_html) # waiting version
# def outer_html(self) -> str:
# return self.wait.for_(query.outer_html)
# --- Assertable --- #
# we need this method here in order to make autocompletion work...
# unfortunately the "base class" version is not enough
示例13: __init__
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def __init__(self, executable_path="chromedriver", port=0,
options=None, service_args=None,
desired_capabilities=None, service_log_path=None,
chrome_options=None):
if "darwin" in sys.platform:
os.environ['PATH'] += ":/Applications/AirtestIDE.app/Contents/Resources/selenium_plugin"
super(WebChrome, self).__init__(chrome_options=chrome_options, executable_path=executable_path,
port=port, options=options, service_args=service_args,
service_log_path=service_log_path, desired_capabilities=desired_capabilities)
self.father_number = {0: 0}
self.action_chains = ActionChains(self)
self.number = 0
self.mouse = Controller()
self.operation_to_func = {"elementsD": self.find_any_element, "xpath": self.find_element_by_xpath, "id": self.find_element_by_id,
"name": self.find_element_by_name, "css": self.find_element_by_css_selector}
示例14: test_06_success
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def test_06_success(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/reconcile')
src = selenium.find_element_by_id('ofx-2-OFX3')
tgt = selenium.find_element_by_id(
'trans-3').find_element_by_class_name('reconcile-drop-target')
# drag and drop
chain = ActionChains(selenium)
chain.drag_and_drop(src, tgt).perform()
# ensure that the OFX div was hidden in the OFX column
src = selenium.find_element_by_id('ofx-2-OFX3')
assert src.is_displayed() is False
# ensure that the OFX div was placed in the drop target
tgt = selenium.find_element_by_id('trans-3')
expected = txn_div(
3,
date(2017, 4, 11),
600,
'BankTwo', 2,
[
['2Periodic', 2, '$590.00'],
['3Periodic', 3, '$10.00']
],
None,
'trans2',
drop_div=ofx_div(
date(2017, 4, 9),
Decimal('600.00'),
'BankTwo', 2,
'Purchase',
'OFX3',
'ofx3-trans2-st1',
trans_id=3
)
)
assert self.normalize_html(tgt.get_attribute('outerHTML')) == expected
# ensure the reconciled variable was updated
assert self.get_reconciled(selenium) == {
3: [2, 'OFX3']
}
示例15: clickSelector
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import ActionChains [as 别名]
def clickSelector(self, selector):
element = self.getElement(selector)
actions = webdriver.ActionChains(self.driver)
actions.move_to_element(element)
actions.click(element)
actions.perform()