本文整理汇总了Python中selenium.webdriver.ActionChains.drag_and_drop方法的典型用法代码示例。如果您正苦于以下问题:Python ActionChains.drag_and_drop方法的具体用法?Python ActionChains.drag_and_drop怎么用?Python ActionChains.drag_and_drop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.ActionChains
的用法示例。
在下文中一共展示了ActionChains.drag_and_drop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_object_to_workflow
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def add_object_to_workflow(self, obj_path, target_name):
""" Add `obj_path` object to `target_name` in workflow. """
for retry in range(3):
try:
items = obj_path.split('.')
parent = items[:-1]
comp = items[-1]
obj = self.get_dataflow_figure(comp, parent)
target = self.find_object_button(target_name)
chain = ActionChains(self.browser)
chain.drag_and_drop(obj.root, target)
chain.perform()
#obj = self.find_object_button(obj_path)
#workflow = self.get_workflow_figure(target_name)
#flow_fig = workflow.flow
#chain = ActionChains(self.browser)
#chain.move_to_element(obj)
#chain.click_and_hold(obj)
#chain.move_to_element(flow_fig)
#chain.move_by_offset(2, 1)
#chain.release(None)
#chain.perform()
except StaleElementReferenceException:
if retry < 2:
logging.warning('add_object_to_workflow:'
' StaleElementReferenceException')
else:
raise
else:
break
示例2: add_object_to_workflow_figure
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def add_object_to_workflow_figure(self, obj_path, target_name, target_page=None):
""" Add `obj_path` object to `target_name` in workflow diagram. """
if target_page is None:
target_page = self
for retry in range(3):
try:
items = obj_path.split('.')
parent = items[:-1]
comp = items[-1]
obj = self.get_dataflow_figure(comp, parent)
workflow = target_page.get_workflow_figure(target_name)
flow_fig = workflow.flow
chain = ActionChains(self.browser)
chain.drag_and_drop(obj.root, flow_fig)
chain.perform()
except StaleElementReferenceException:
if retry < 2:
logging.warning('add_object_to_workflow_figure:'
' StaleElementReferenceException')
else:
raise
else:
break
示例3: add_library_item_to_dataflow
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [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
示例4: when_i_drag_pill_from_time1_to_time2
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def when_i_drag_pill_from_time1_to_time2(step, pill, time1, time2):
# get the data id for this pill
pill = find_pill(pill)
assert pill is not None, "No pill named %s found." % pill
draggable = pill.find_element_by_css_selector(
"div.pill-image span.draggable")
assert draggable is not None, (
"This pill is not constructed properly: %s" % pill)
data_id = draggable.get_attribute("data-id")
bucket = get_bucket(time1)
assert bucket is not None, (
"Source time slot must be specified as day or evening. "
"No time slot called %s found" % time)
dest = get_bucket(time2)
assert dest is not None, (
"Destination time slot must be specified as day or evening. "
"No time slot called %s found" % time)
a = bucket.find_elements_by_css_selector('span.trashable')
assert len(a) > 0, (
"Expected at least 1 pill in bucket %s, instead it "
"contains %s pills" % (bucket, len(a)))
action = False
for dropped in a:
if (data_id == dropped.get_attribute("data-id")):
# found it, now, drag it to the second bucket
action_chains = ActionChains(world.browser)
action_chains.drag_and_drop(dropped, dest).perform()
action = True
assert action, (
"No dropped pills named %s found in %s slot" % (pill, time1))
示例5: test_en_classify_products_function_drag_and_drop
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def test_en_classify_products_function_drag_and_drop(self):
driver = self.driver
gb_login(self)
driver.get(self.base_url + "/ev/classifyproducts")
driver.find_element_by_xpath("//li[@id='categoryCol_category514']/div/span").click()
# Verify process missing.
try:
self.assertTrue(
self.is_element_present(
By.CSS_SELECTOR, "#categoryCol_subcategory515 > div.itemContent.subCategoryBg > div.handle"
)
)
except AssertionError as e:
self.verificationErrors.append(str(e))
try:
self.assertTrue(
self.is_element_present(
By.CSS_SELECTOR, "#categoryCol_category517 > div.categoryBg.itemContent > div.blockText"
)
)
except AssertionError as e:
self.verificationErrors.append(str(e))
element = driver.find_element_by_css_selector(
"#categoryCol_subcategory515 > div.itemContent.subCategoryBg > div.handle"
)
target = driver.find_element_by_css_selector(
"#categoryCol_category517 > div.categoryBg.itemContent > div.blockText"
)
action_chains = ActionChains(driver)
action_chains.drag_and_drop(element, target)
示例6: test_drag
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def test_drag(self):
global driver
element = driver.find_element_by_id("draggable")
target = driver.find_element_by_id("div2")
actions = ActionChains(driver)
actions.drag_and_drop(element, target).perform()
self.assertEqual("You are definitely not a bot!", driver.find_element_by_id("message").text)
示例7: add_library_item_to_dataflow
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [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
示例8: when_i_drop_pill_index_onto_time
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def when_i_drop_pill_index_onto_time(step, index, time):
idx = int(index) - 1
a = world.firefox.find_elements_by_css_selector("div.pill")
assert len(a) > idx, "Can't find pill %s as there are only %s pills in the list" % (index, len(a))
pill = a[idx]
draggable = pill.find_element_by_css_selector("div.pill-image span.draggable")
assert draggable is not None, "This pill is not constructed properly: %s" % pill
bucket = get_bucket(time)
assert bucket is not None, "Time slot must be specified as day or evening. " "No time slot called %s found" % time
action_chains = ActionChains(world.firefox)
action_chains.drag_and_drop(draggable, bucket).perform()
示例9: drag_item_to_zone
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def drag_item_to_zone(self, item_value, zone_id):
"""
Drag item to desired zone using mouse interaction.
zone_id=None means drag item back to the item bank.
"""
element = self._get_item_by_value(item_value)
if zone_id is None:
target = self._get_item_bank()
else:
target = self._get_zone_by_id(zone_id)
action_chains = ActionChains(self.browser)
action_chains.drag_and_drop(element, target).perform()
示例10: test_en_upload_media_function_drag_and_drop
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def test_en_upload_media_function_drag_and_drop(self):
driver = self.driver
gb_login(self)
driver.get(self.base_url + "/ev/uploadmedia")
try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "#mediaGroup_mediaGroup604 > div.mediaGroupBg.itemContent > div.blockText"))
except AssertionError as e: self.verificationErrors.append(str(e))
try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "#media_medium187 > div.mediaBg.itemContent > div.blockText"))
except AssertionError as e: self.verificationErrors.append(str(e))
element = driver.find_element_by_css_selector("#media_medium187 > div.mediaBg.itemContent > div.handle")
target = driver.find_element_by_css_selector("#mediaGroup_mediaGroup604 > div.mediaGroupBg.itemContent > div.blockText")
action_chains = ActionChains(driver)
action_chains.drag_and_drop(element, target);
示例11: when_i_drop_pill_onto_time
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def when_i_drop_pill_onto_time(step, pill, time):
pill = find_pill(pill)
assert pill is not None, "No pill named %s found." % pill
# get the draggable span within
draggable = pill.find_element_by_css_selector("div.pill-image span.draggable")
assert draggable is not None, "This pill is not constructed properly: %s" % pill
bucket = get_bucket(time)
assert bucket is not None, "Time slot must be specified as day or evening. " "No time slot called %s found" % time
action_chains = ActionChains(world.firefox)
action_chains.drag_and_drop(draggable, bucket).perform()
示例12: test_en_assign_accessory_function_assign
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def test_en_assign_accessory_function_assign(self):
driver = self.driver
gb_login(self)
driver.get(self.base_url + "/ev/assignaccessories")
driver.find_element_by_xpath("//li[@id='categories_category517']/div/span").click()
driver.find_element_by_xpath("//li[@id='accessories_category514']/div/span").click()
try: self.assertTrue(self.is_element_present(By.XPATH, "//li[@id='accessories_accessory636']/div/div"))
except AssertionError as e: self.verificationErrors.append(str(e))
try: self.assertTrue(self.is_element_present(By.XPATH, "//li[@id='products_product637']/div/div"))
except AssertionError as e: self.verificationErrors.append(str(e))
element = driver.find_element_by_xpath("//li[@id='accessories_accessory636']/div/div")
target = driver.find_element_by_xpath("//li[@id='products_product637']/div/div")
action_chains = ActionChains(driver)
action_chains.drag_and_drop(element, target);
示例13: test_en_setup_users_or_groups_function_assign_uassign_user_group
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def test_en_setup_users_or_groups_function_assign_uassign_user_group(self):
driver = self.driver
gb_login(self)
driver.get(self.base_url + "/ev/setupusersorgroups")
try: self.assertTrue(self.is_element_present(By.XPATH, "//li[@id='userGroup_userGroup"+testUserGroupIdValue+"']/div/div"))
except AssertionError as e: self.verificationErrors.append(str(e))
#driver.find_element_by_xpath("//li[@id='hierarchy_storeGroup202']/div/span").click()
#try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "#hierarchy_store203 > div.itemContent.storeBg > div.blockText"))
#except AssertionError as e: self.verificationErrors.append(str(e))
try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "#hierarchy_store"+assignStoreIdValue+" > div.itemContent.storeBg > div.blockText"))
except AssertionError as e: self.verificationErrors.append(str(e))
element = driver.find_element_by_xpath("//li[@id='userGroup_userGroup"+testUserGroupIdValue+"']/div/div")
target = driver.find_element_by_css_selector("#hierarchy_store"+assignStoreIdValue+" > div.itemContent.storeBg > div.blockText")
action_chains = ActionChains(driver)
action_chains.drag_and_drop(element, target);
开发者ID:yueran,项目名称:EV-SeleniumTest,代码行数:17,代码来源:en_SetupUsersOrGroups_Function_UsersGroups_AssignUassignUserGroup.py
示例14: test_edit_site
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def test_edit_site(self):
print "Create site test is commencing."
wait = WebDriverWait(self.driver, self.waitTime)
self.driver.get(self.url)
print "Starting logging in."
wait.until(EC.element_to_be_clickable((By.ID, "login-button"))).click()
wait.until(EC.element_to_be_clickable((By.ID, "weebly-username"))).click()
wait.until(EC.element_to_be_clickable((By.ID, "weebly-password"))).click()
Username = self.driver.find_element_by_id("weebly-username")
Username.send_keys(self.email)
Password = self.driver.find_element_by_id("weebly-password")
Password.send_keys(self.password)
wait.until(EC.element_to_be_clickable((By.XPATH, "//form[@id='weebly-login']/p[4]/input"))).click()
print "Selecting Site to edit."
wait.until(EC.presence_of_element_located((By.LINK_TEXT, "Jon's Site")))
self.driver.find_element_by_link_text("Jon's Site").click()
print "Finding another text object from toolbar and starting drag and drop."
wait.until(EC.presence_of_element_located((By.ID, "secondlist")))
self.driver.find_element_by_xpath("//li[2]/div[2]").click()
text = self.driver.find_element_by_xpath("//li[2]/div[2]")
text_target = self.driver.find_element_by_id("secondlistParent")
drag_text = ActionChains(self.driver)
drag_text.drag_and_drop(text, text_target).perform()
time.sleep(2)
self.driver.find_element_by_xpath("//li[3]/div[2]/div/div").click()
time.sleep(2)
self.driver.find_element_by_xpath("//li[3]/div[2]/div/div").clear()
time.sleep(2)
self.driver.find_element_by_xpath("//li[3]/div[2]/div/div").send_keys(
"Drag and drop text area testing text input for third item."
)
time.sleep(2)
self.driver.find_element_by_id("secondlist").click()
time.sleep(5)
print "Drag and drop should now be complete."
print "Exit the editor."
wait.until(EC.element_to_be_clickable((By.XPATH, "//li[@id='more-drop-button']/a/span"))).click()
wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Exit Editor"))).click()
print "Exited the editor"
print "Log out"
wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Logout"))).click()
print "Logged out!"
示例15: test_reorder_components
# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import drag_and_drop [as 别名]
def test_reorder_components(self):
self.add_component('hypothesis', 'first')
self.add_component('hypothesis', 'second')
self.driver.get(self.project_url)
# Second method: by element
ac = ActionChains(self.driver)
a = self.driver.find_element_by_css_selector('#Nodes li:first-child')
b = self.driver.find_element_by_css_selector('#Nodes li:last-child')
ac.drag_and_drop(a, b).perform()
self.driver.get(self.project_url)
self.assertEqual(
self.get_element('#Nodes li:first-child').text,
'second',
)