本文整理汇总了Python中selenium.webdriver.common.action_chains.ActionChains.move_by_offset方法的典型用法代码示例。如果您正苦于以下问题:Python ActionChains.move_by_offset方法的具体用法?Python ActionChains.move_by_offset怎么用?Python ActionChains.move_by_offset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.common.action_chains.ActionChains
的用法示例。
在下文中一共展示了ActionChains.move_by_offset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hover
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def hover(self):
element = self._root_element.find_element(*self._name_locator)
# Workaround for Firefox
chain = ActionChains(self.selenium).move_to_element(element)
if "firefox" in self.selenium.desired_capabilities["browserName"]:
chain.move_by_offset(0, element.size['height'])
chain.perform()
示例2: setup
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def setup(self):
try:
button = self.window.find_element_by_link_text("Cone")
except NoSuchElementException:
print >>sys.stderr, "fatal error: could not find the 'Cone' button!"
print >>sys.stderr, "(visit %s to diagnose the problem)" % (url)
raise vtkwebtest.WebTest.Abort()
button.click()
# Wait for the vtkweb process to start (but time out after 10 seconds).
if not vtkwebtest.wait_with_timeout(delay=0.5, limit=10, criterion=found_viewport(self.window)):
print >>sys.stderr, "fatal error: timed out while waiting for vtkweb process to start"
raise vtkwebtest.WebTest.Abort()
# Grab the viewport element so we know where to put the mouse.
div = self.window.find_element_by_id("viewport")
# Click-and-drag on the cone to change its position a bit.
drag = ActionChains(self.window)
drag.move_to_element(div)
drag.click_and_hold()
drag.move_by_offset(-300, 100)
drag.release()
drag.perform()
# Give the page some time to update the image.
time.sleep(1)
示例3: test_lasso_select
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def test_lasso_select(output_file_url, selenium):
plot = generate_plot()
#limit to one callback on click release
plot.add_tools(LassoSelectTool(select_every_mousemove=False))
# Save the plot and start the test
save(plot)
selenium.get(output_file_url)
assert has_no_console_errors(selenium)
# Drag a lasso selection area around middle point
canvas = selenium.find_element_by_tag_name('canvas')
actions = ActionChains(selenium)
actions.move_to_element_with_offset(canvas, PLOT_DIM * 0.25, PLOT_DIM * 0.25)
actions.click_and_hold()
actions.move_by_offset(0, PLOT_DIM * 0.5)
actions.move_by_offset(PLOT_DIM * 0.5, 0)
actions.move_by_offset(0, PLOT_DIM * -0.5)
actions.release()
actions.perform()
# Get the alert from box select and assert that the middle item is selected
alert = selenium.switch_to_alert()
assert alert.text == 'middle'
示例4: set_credit_score_range
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def set_credit_score_range(self, slider_direction):
actions = ActionChains(self.driver)
# Get the pixel width of the slider control
slider_element = self.driver.find_element_by_xpath(SLIDER)
slider_width = int(slider_element.get_attribute("scrollWidth"))
self.logger.info("width: %s" % slider_width)
element = self.driver.find_element_by_xpath(SLIDER_HANDLE)
# Move the slider 1/4 of the total width to the right
if(slider_direction == "right"):
xOffset = (slider_width/4)
# Move the slider 1/4 of the total width to the left
elif(slider_direction == "left"):
xOffset = (slider_width/-4)
# Move the slider 1/2 of the total width to the left
elif(slider_direction == "lowest"):
xOffset = (slider_width/-2)
# Move the slider 1/2 of the total width to the right
elif(slider_direction == "highest"):
xOffset = (slider_width/2)
actions.click_and_hold(element)
actions.move_by_offset(xOffset, 0)
actions.release()
actions.perform()
示例5: hover
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def hover(self):
element = self._root_element.find_element(*self._name_locator)
# Workaround for Firefox
chain = ActionChains(self.selenium).move_to_element(element)
if hasattr(self.selenium, "firefox_profile"):
chain.move_by_offset(0, element.size['height'])
chain.perform()
示例6: move
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def move(self, delta_x, delta_y):
""" Move dialog. """
chain = ActionChains(self.browser)
chain.click_and_hold(self('dialog_title').element)
chain.move_by_offset(delta_x, delta_y)
chain.release(None)
chain.perform()
示例7: bot_mitigation
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def bot_mitigation(webdriver):
""" performs three optional commands for bot-detection mitigation when getting a site """
# bot mitigation 1: move the randomly around a number of times
window_size = webdriver.get_window_size()
num_moves = 0
num_fails = 0
while num_moves < NUM_MOUSE_MOVES + 1 and num_fails < NUM_MOUSE_MOVES:
try:
if num_moves == 0: #move to the center of the screen
x = int(round(window_size['height']/2))
y = int(round(window_size['width']/2))
else: #move a random amount in some direction
move_max = random.randint(0,500)
x = random.randint(-move_max, move_max)
y = random.randint(-move_max, move_max)
action = ActionChains(webdriver)
action.move_by_offset(x, y)
action.perform()
num_moves += 1
except MoveTargetOutOfBoundsException:
num_fails += 1
#print "[WARNING] - Mouse movement out of bounds, trying a different offset..."
pass
# bot mitigation 2: scroll in random intervals down page
scroll_down(webdriver)
# bot mitigation 3: randomly wait so that page visits appear at irregular intervals
time.sleep(random.randrange(RANDOM_SLEEP_LOW, RANDOM_SLEEP_HIGH))
示例8: put_element_on_grid
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def put_element_on_grid(workspace_page, element_str):
'''find and get the 'assembly', and the div for the grid object'''
browser = workspace_page.browser
for retry in range(3):
try:
assembly = workspace_page.find_library_button(element_str)
chain = ActionChains(browser)
chain.click_and_hold(assembly)
chain.move_by_offset(-100, 0).perform()
except StaleElementReferenceException:
if retry < 2:
logging.warning('put_element_on_grid %s:'
' StaleElementReferenceException', element_str)
else:
raise
else:
break
grid = browser.find_element_by_xpath('//div[@id="-dataflow"]')
check_highlighting(grid, True, "Grid")
release(chain)
# deal with the modal dialog
name = NameInstanceDialog(workspace_page).create_and_dismiss()
# make sure it is on the grid
ensure_names_in_workspace(workspace_page, [name],
"Dragging '" + element_str + "' to grid did not produce a new element on page")
return name
示例9: _test_drop_on_component_editor_grid
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def _test_drop_on_component_editor_grid(browser):
project_dict, workspace_page = startup(browser)
workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top')
top = workspace_page.get_dataflow_figure('top', '')
workspace_page.set_library_filter('Assembly') # put Assembly at top of lib
assembly = workspace_page.find_library_button('Assembly')
editor = top.editor_page(double_click=False, base_type='Assembly')
editor.show_dataflow()
editor_top = workspace_page.get_dataflow_fig_in_globals('top')
# sort through these to find the correct 'top'
chain = ActionChains(browser)
chain.click_and_hold(assembly)
chain.move_to_element(editor_top('header').find_element_by_xpath("..")).perform()
chain.move_by_offset(200, 1).perform()
chain.release(None).perform()
# don't bother checking to see if it appeared,
# the UI box will appear and screw the test if it did
closeout(project_dict, workspace_page)
示例10: add_to_shimo
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def add_to_shimo(content):
driver = webdriver.Chrome(sys.argv[1]) # Optional argument, if not specified will search path.
#driver.add_cookie({'name' : 'session', 'value' : 'eyJfaWQiOnsiIGIiOiJaalUyTm1aak5EVTRPRE5qWWpVNU9HWmtNalZoWmpBNE4yUTNaR016TkRrPSJ9fQ', 'path' : '/'})
driver.implicitly_wait(0)
driver.get('https://www.shimo.im/')
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
driver.get('https://www.shimo.im/doc/g8XvnVEvCtEWnvrB')
try:
search_box = driver.find_element_by_class_name('locate')
mouse = ActionChains(driver)
mouse.move_to_element_with_offset(search_box, 0, 0)
mouse.click()
mouse.send_keys(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ': %s\n' % content)
mouse.perform()
except:
mouse = ActionChains(driver)
mouse.move_by_offset(290, 400)
mouse.click()
mouse.send_keys(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ': %s\n' % content)
mouse.perform()
time.sleep(5)
driver.quit()
示例11: add_homework_problems
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def add_homework_problems(self, driver, problems):
""""""
wait = WebDriverWait(driver, Assignment.WAIT_TIME)
driver.find_element(By.ID, "problems-select").click()
wait.until(expect.visibility_of_element_located((By.XPATH, '//span[text()="Add Problems"]')))
self.select_sections(driver, list(problems.keys()))
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.find_element(By.XPATH, '//button[contains(@class,"-show-problems")]').click()
all_available = self.find_all_questions(driver, problems)
using = []
# print('AHP - Selection list: %s' % selections)
for section in problems:
if problems is None or str(problems).lower() == "none":
print("%s: No exercises (%s)" % (section, problems[section]))
continue
# Set maximum Tutor-selected problems
if section == "tutor":
print("Using %s Tutor selections" % problems[section])
self.set_tutor_selections(driver, problems)
# Select all exercises in the section
elif problems[section] == "all":
print("Selecting all from %s" % section)
available = self.get_chapter_list(all_available, section) if "ch" in section else all_available[section]
for ex in available:
using.append(ex)
# Select between X and Y exercises, inclusive, from the section
elif type(problems[section]) == tuple:
low, high = problems[section]
total = random.randint(int(low), int(high))
print("Selecting %s random from %s (%s to %s)" % (total, section, low, high))
available = self.get_chapter_list(all_available, section) if "ch" in section else all_available[section]
for i in range(total):
ex = random.randint(0, len(available) - 1)
using.append(available[ex])
available.remove(available[ex])
# Select the first X exercises from the section
elif type(problems[section]) == int:
print("Selecting first %s from %s" % (problems[section], section))
available = self.get_chapter_list(all_available, section) if "ch" in section else all_available[section]
for position in range(problems[section]):
using.append(available[position])
elif problems[section] is list:
print("Adding %s custom if available" % len(problems[section]))
for ex in problems[section]:
for section in all_available:
if ex in all_available[section]:
using.append(ex)
for exercise in set(using):
ac = ActionChains(driver)
time.sleep(0.5)
ac.move_to_element(driver.find_element(By.XPATH, '//span[contains(@data-reactid,"%s")]' % exercise))
ac.move_by_offset(0, -80)
ac.click()
ac.perform()
ActionChains(driver).move_to_element(
driver.find_element(By.XPATH, '//span[text()="Tutor Selections"]')
).move_by_offset(0, -80).perform()
wait.until(expect.visibility_of_element_located((By.XPATH, '//*[text()="Next"]'))).click()
示例12: fireEvent
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def fireEvent(self, target, value):
"""
"""
if (value == 'blur'):
target_elem = self._find_target(target)
actions = ActionChains(self.driver)
actions.move_to_element(target_elem)
actions.move_by_offset(target_elem.size["width"] / 2 + 1, 0)
actions.click().perform()
示例13: __click_cordinate
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def __click_cordinate(cls, target, x, y):
off_x = int(target.size["width"]) / 2
off_y = int(target.size["height"]) / 2
actions = ActionChains(cls.driver)
actions.move_to_element(target)
actions.move_by_offset(x - off_x, y - off_y)
actions.click()
actions.move_to_element(target)
actions.perform()
示例14: mistake
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def mistake(self):
action = ActionChains(self.driver)
element = self.driver.find_element_by_xpath(self.selectors['first_paragraph'])
action.click_and_hold(element)
action.move_by_offset(0, -20)
action.perform()
element.send_keys(Keys.CONTROL + Keys.ENTER)
"""nn-article-header '//*[@class="nn-article-header"]'"""
示例15: i_select_a_highlight_on_the_first_page_of_document
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import move_by_offset [as 别名]
def i_select_a_highlight_on_the_first_page_of_document(step, docnum):
doc = csss('.edit-document')[int(docnum) - 1]
el = css("canvas.page-image", doc)
chain = ActionChains(world.browser)
chain.move_to_element_with_offset(el, 20, 20)
chain.click_and_hold(None)
chain.move_by_offset(300, 100)
chain.release(None)
chain.perform()