本文整理汇总了Python中selenium.webdriver.ActionChains.click_and_hold方法的典型用法代码示例。如果您正苦于以下问题:Python ActionChains.click_and_hold方法的具体用法?Python ActionChains.click_and_hold怎么用?Python ActionChains.click_and_hold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.ActionChains
的用法示例。
在下文中一共展示了ActionChains.click_and_hold方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_library_item_to_dataflow
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def add_library_item_to_dataflow(self, item_name, instance_name, check=True, offset=None, prefix=None):
""" Add component `item_name`, with name `instance_name`. """
library_item = self.get_library_item(item_name)
target = WebDriverWait(self.browser, TMO).until(
lambda browser: browser.find_element_by_xpath("//*[@id='-dataflow']")
)
offset = offset or (90, 90)
chain = ActionChains(self.browser)
if False:
chain.drag_and_drop(library_item, target)
else:
chain.click_and_hold(library_item)
chain.move_to_element_with_offset(target, offset[0], offset[1])
chain.release(None)
chain.perform()
page = ValuePrompt(self.browser, self.port)
page.set_value(instance_name)
# Check that the prompt is gone so we can distinguish a prompt problem
# from a dataflow update problem.
time.sleep(0.25)
self.browser.implicitly_wait(1) # We don't expect to find anything.
try:
eq(len(self.browser.find_elements(*page("prompt")._locator)), 0)
finally:
self.browser.implicitly_wait(TMO)
retval = None
if check: # Check that it's been added.
retval = WebDriverWait(self.browser, TMO).until(
lambda browser: self.get_dataflow_figure(instance_name, prefix)
)
return retval
示例2: _test_reorder_file_bar
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def _test_reorder_file_bar(self, page):
page.add_file([x for x in FILES if x.name == 'test.jpg'][0])
WebDriverWait(page.driver, 3).until(
ec.visibility_of_element_located(
(
By.CSS_SELECTOR,
'div.grid-canvas div.ui-widget-content.slick-row.odd'
)
)
)
ac = ActionChains(page.driver)
a = page.driver.find_elements_by_css_selector(
'DIV.container DIV.slick-header.ui-state-default DIV.slick-header-columns.ui-sortable SPAN.slick-column-name'
)[3]
b = page.driver.find_elements_by_css_selector(
'DIV.container DIV.slick-header.ui-state-default DIV.slick-header-columns.ui-sortable SPAN.slick-column-name'
)[0]
ac.click_and_hold(a).perform()
a_chain = ActionChains(page.driver)
a_chain.move_to_element(b).perform()
a_chain.release(b).perform()
downloads = page.driver.find_element_by_css_selector(
'div.grid-canvas div.ui-widget-content.slick-row.odd DIV.slick-cell.l0.r0'
).text
self.assertIn('0', downloads)
page.close()
示例3: drag_scroll_by_css
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def drag_scroll_by_css(browser, offset_x, offset_y):
scroll, height = wait_element_present(browser)
action = ActionChains(browser)
try:
action.click_and_hold(scroll[0]).move_by_offset(int(offset_x), int(offset_y) + 1).release().perform()
except AssertionError:
drag_scroll_by_css(browser, offset_x, offset_y)
示例4: test_history
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def test_history(self):
'''
1. Get the outer div id of the activecode component
2. Find the run button using its class name
3. Run the example
4. Check the output from the ac_output element
:return:
'''
self.driver.get(self.host + "/index.html")
t1 = self.driver.find_element_by_id("test1")
self.assertIsNotNone(t1)
rb = t1.find_element_by_class_name("run-button")
self.assertIsNotNone(rb)
rb.click()
ta = t1.find_element_by_class_name("cm-s-default")
self.assertIsNotNone(ta)
self.driver.execute_script("""edList['test1'].editor.setValue("print('GoodBye')")""")
WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "run-button")))
rb.click()
output = t1.find_element_by_class_name("ac_output")
self.assertEqual(output.text.strip(),"GoodBye")
move = ActionChains(self.driver)
slider = t1.find_element_by_class_name("ui-slider")
width = slider.size['width']
slider = t1.find_element_by_class_name("ui-slider-handle")
move.click_and_hold(slider).move_by_offset(-width,0).release().perform()
rb.click()
output = t1.find_element_by_class_name("ac_output")
self.assertEqual(output.text.strip(), "Hello World")
示例5: drag
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def drag(self, x_offset, y_offset):
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.click_and_hold()
actions.move_by_offset(x_offset, y_offset)
actions.release().perform()
示例6: put_element_on_grid
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def put_element_on_grid(self, type_str):
'''find 'type_str' in the Library, drag and drop it onto the grid'''
browser = self.browser
grid = browser.find_element_by_xpath('//div[@id="-dataflow"]')
for retry in range(3):
try:
objtype = self.find_library_button(type_str)
chain = ActionChains(browser)
chain.click_and_hold(objtype)
chain.move_to_element_with_offset(grid, 10, 10).perform()
except StaleElementReferenceException:
if retry < 2:
logging.warning('put_element_on_grid %s:'
' StaleElementReferenceException', type_str)
else:
raise
else:
break
self.check_highlighting(grid, True, "Grid")
self.release(chain)
# deal with the modal dialog
name = NameInstanceDialog(self).create_and_dismiss()
# make sure it is on the grid
self.ensure_names_in_workspace([name],
"Dragging '" + type_str +
"' to grid did not produce a new element on page")
return name
示例7: setup_google_driver
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def setup_google_driver():
driver = webdriver.Firefox()
driver.get('http://google.com')
time.sleep(0.2)
#driver.maximize_window()
time.sleep(3)
driver.get('http://google.com/preferences')
time.sleep(2)
radios = driver.find_elements_by_css_selector('div.jfk-radiobutton')
radio = radios[-1]
radio.click()
time.sleep(1.2)
slider = driver.find_element_by_css_selector('div.goog-slider-scale')
dims = slider.size
width = dims['width']
move = ActionChains(driver)
slider2 = driver.find_element_by_css_selector('div.goog-slider-scale')
for i in range(4):
time.sleep(0.1)
move.click_and_hold(slider2).move_by_offset(width//9,0).release().perform()
move.click_and_hold(slider2).move_by_offset(width//2,0).release().perform()
time.sleep(1.5)
driver.switch_to_default_content()
#save settings
elems = driver.find_elements_by_id('form-buttons')
elems[0].find_elements_by_tag_name('div')[0].click()
alert = driver.switch_to_alert()
time.sleep(0.91)
alert.accept()
time.sleep(1)
return driver
示例8: zoom_selection
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [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()
示例9: reorder_column_by_index
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def reorder_column_by_index(browser, index, left_or_right, offsetx):
chains = ActionChains(browser)
wait_for_elem(browser, "return $('.ember-table-content-container')")
element = browser.execute_script(
"return $('.ember-table-content-container .ember-table-content:eq(" + str(index) + ")')")
if left_or_right == "left":
chains.click_and_hold(element[0]).move_by_offset(-int(offsetx), 0).release().perform()
else:
chains.click_and_hold(element[0]).move_by_offset(int(offsetx), 0).release().perform()
示例10: reorder_column_with_offset
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def reorder_column_with_offset(browser, css, index, rightOrLeft, offset):
columnsHeader = find_elements_by_css(browser, css)
action_chains = ActionChains(browser)
if str(rightOrLeft) == "left":
action_chains.click_and_hold(columnsHeader[int(index) - 1]).move_by_offset(-int(offset), 0).move_by_offset(10,
0).release().perform()
else:
action_chains.click_and_hold(columnsHeader[int(index) - 1]).move_by_offset(int(offset), 0).move_by_offset(-10,
0).release().perform()
示例11: drag_hold_column
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def drag_hold_column(step, column_name, left_or_right, offsetx):
with AssertContextManager(step):
chains = ActionChains(world.browser)
wait_for_elem(world.browser, "return $('.ember-table-content-container')")
element = world.browser.execute_script(
"return $('.ember-table-content-container .ember-table-content:contains(" + column_name + ")')")
if left_or_right == "left":
chains.click_and_hold(element[0]).move_by_offset(-int(offsetx), 0).perform()
else:
chains.click_and_hold(element[0]).move_by_offset(int(offsetx), 0).perform()
示例12: add_library_item_to_dataflow
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def add_library_item_to_dataflow(self, item_name, instance_name,
check=True, offset=None, prefix=None,
args=None):
""" Add component `item_name`, with name `instance_name`. """
offset = offset or (90, 90)
xpath = "//*[@id='-dataflow']"
library_item = self.get_library_item(item_name)
target = WebDriverWait(self.browser, TMO).until(
lambda browser: browser.find_element_by_xpath(xpath))
for retry in range(3):
try:
chain = ActionChains(self.browser)
if False:
chain.drag_and_drop(library_item, target)
else:
chain.click_and_hold(library_item)
chain.move_to_element_with_offset(target,
offset[0], offset[1])
chain.release(None)
chain.perform()
except StaleElementReferenceException:
if retry < 2:
logging.warning('add_library_item_to_dataflow:'
' StaleElementReferenceException')
library_item = self.get_library_item(item_name)
target = WebDriverWait(self.browser, TMO).until(
lambda browser: browser.find_element_by_xpath(xpath))
else:
raise
else:
break
page = ArgsPrompt(self.browser, self.port)
page.set_name(instance_name)
if args is not None:
for i, arg in enumerate(args):
page.set_argument(i, arg)
page.click_ok()
# Check that the prompt is gone so we can distinguish a prompt problem
# from a dataflow update problem.
time.sleep(0.25)
self.browser.implicitly_wait(1) # We don't expect to find anything.
try:
eq(len(self.browser.find_elements(*page('prompt')._locator)), 0)
finally:
self.browser.implicitly_wait(TMO)
retval = None
if check: # Check that it's been added.
retval = WebDriverWait(self.browser, TMO).until(
lambda browser: self.get_dataflow_figure(instance_name,
prefix))
return retval
示例13: action_elements_events
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def action_elements_events(self, element_menu, drag_divs):
action = ActionChains(self.driver)
action.move_to_element(element_menu).click(element_menu)
action.click_and_hold(drag_divs)
action.move_by_offset(35, 35)
action.move_by_offset(15, 20)
action.move_by_offset(55, 15)
action.release()
action.perform()
event_start = self.driver.find_element_by_xpath("//li[@id = 'event-start']/span[2]").text
event_drag = self.driver.find_element_by_xpath("//li[@id='event-drag']/span[2]").text
event_stop = self.driver.find_element_by_xpath("//li[@id = 'event-stop']/span[2]").text
return event_start, event_drag, event_stop
示例14: drag_element_to
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def drag_element_to(self, element, drag_to, center):
'''Drag one element over to another element'''
chain = ActionChains(self.browser)
chain.move_to_element(element)
chain.click_and_hold(element)
if center:
# move to center of element
chain.move_to_element(drag_to)
else:
# move to offset from top left of element
chain.move_to_element_with_offset(drag_to, 2, 2)
chain.perform()
return chain
示例15: connect
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import click_and_hold [as 别名]
def connect(self, src, dst):
""" Return :class:`ConnectionsPage` for connecting `src` to `dst`. """
chain = ActionChains(self.browser)
chain.click_and_hold(src.output_port)
# Using root rather than input_port since for some reason
# even using a negative Y offset can select the parent's input.
chain.move_to_element(dst.input_port)
chain.release(None)
chain.perform()
parent, dot, srcname = src.pathname.rpartition(".")
parent, dot, dstname = dst.pathname.rpartition(".")
editor_id = "ConnectionsFrame-%s" % (parent)
editor_id = editor_id.replace(".", "-")
return ConnectionsPage(self.browser, self.port, (By.ID, editor_id))