本文整理匯總了Python中selenium.webdriver.common.action_chains.ActionChains方法的典型用法代碼示例。如果您正苦於以下問題:Python action_chains.ActionChains方法的具體用法?Python action_chains.ActionChains怎麽用?Python action_chains.ActionChains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類selenium.webdriver.common.action_chains
的用法示例。
在下文中一共展示了action_chains.ActionChains方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_dbm3002_rotate
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def test_dbm3002_rotate(dash_duo):
app = dash.Dash(__name__)
app.layout = html.Div([
dash_bio.Molecule3dViewer(
id=_COMPONENT_ID,
modelData=_model_data,
styles=_styles_data
)
])
dash_duo.start_server(app)
dash_duo.wait_for_element('#' + _COMPONENT_ID)
mol3d = dash_duo.find_element('#' + _COMPONENT_ID + ' canvas')
ac = ActionChains(dash_duo.driver)
ac.drag_and_drop_by_offset(mol3d, 100, 50).perform()
dash_duo.percy_snapshot('test-mol3d_rotate')
示例2: prepare
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def prepare(self):
self.browser.get("http://music.163.com")
# self.browser.set_window_size(1920, 1080)
action = action_chains.ActionChains(self.browser)
action.send_keys()
self.browser.switch_to.frame("contentFrame")
self.browser.execute_script("document.getElementById('index-enter-default').click()")
self.browser.switch_to.default_content()
sleep(0.5)
self.browser.execute_script("document.querySelectorAll('[data-type=\"netease\"]')[0].click()")
sleep(0.5)
element = self.browser.find_element_by_css_selector('input[class="js-input u-txt"]')
element.send_keys(self.config.account)
sleep(0.5)
element = self.browser.find_element_by_css_selector('input[type=\"password\"]')
element.send_keys(self.config.password)
sleep(0.5)
self.browser.execute_script("document.querySelectorAll('[data-action=\"login\"]')[6].click()")
print("login sucess")
示例3: move_to_element
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def move_to_element(self, element):
"""
[Internal]
Move focus to element on the screen.
:param element: Selenium element
:type element: Selenium object
Usage:
>>> #Defining an element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method
>>> self.scroll_to_element(element())
"""
ActionChains(self.driver).move_to_element(element).perform()
示例4: _move_simulation
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def _move_simulation(device, e):
try:
action = ActionChains(device)
action.click_and_hold(e).perform()
# action.reset_actions()
offset = 21
for i in range(210 / offset):
ActionChains(device).move_by_offset(xoffset=offset, yoffset=0).perform()
time.sleep((offset - i) / 50)
action.release().perform()
action.reset_actions()
except Exception as e:
if DEBUG: print e
# 模擬輸入
示例5: clear_chat
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def clear_chat(self, name):
self.browser.find_element_by_css_selector("._3FRCZ").send_keys(name+Keys.ENTER)
menu_xpath = "/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[3]/div/span"
WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
(By.XPATH, menu_xpath)))
menu = self.browser.find_element_by_xpath(menu_xpath)
menu.click()
chains = ActionChains(self.browser)
for i in range(4):
chains.send_keys(Keys.ARROW_DOWN)
chains.send_keys(Keys.ENTER)
chains.perform()
clear_xpath = '//*[@id="app"]/div/span[2]/div/div/div/div/div/div/div[2]/div[2]'
WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
(By.XPATH, clear_xpath)))
self.browser.find_element_by_xpath(clear_xpath).click()
# override the timeout
示例6: test_dbsp001_rotate
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def test_dbsp001_rotate(dash_duo):
app = dash.Dash(__name__)
app.layout = html.Div(
dash_bio.Speck(
id=_COMPONENT_ID,
data=_data
)
)
dash_duo.start_server(app)
dash_duo.wait_for_element('#' + _COMPONENT_ID)
speck = dash_duo.find_element('#' + _COMPONENT_ID + ' canvas')
ac = ActionChains(dash_duo.driver)
ac.move_to_element(speck).drag_and_drop_by_offset(
speck, 150, 200).perform()
dash_duo.percy_snapshot('test-speck_rotate')
示例7: test_dbsp002_click_and_drag
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def test_dbsp002_click_and_drag(dash_duo):
app = dash.Dash(__name__)
app.layout = html.Div(
dash_bio.Speck(
id=_COMPONENT_ID,
data=_data
)
)
dash_duo.start_server(app)
dash_duo.wait_for_element('#' + _COMPONENT_ID)
speck = dash_duo.find_element('#' + _COMPONENT_ID + ' canvas')
ac = ActionChains(dash_duo.driver)
ac.move_to_element(speck).key_down(Keys.SHIFT).drag_and_drop_by_offset(
speck, -50, 100).key_up(Keys.SHIFT).perform()
dash_duo.percy_snapshot('test-speck_click_and_drag')
示例8: random_youtube
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def random_youtube():
iterations = randint(1,8)
count = 0
while(1):
item = words[randint(0,len(words))]
driver.get("https://www.youtube.com/results?search_query="+item)
element = driver.find_element_by_class_name('yt-uix-tile-link')
element.click()
actions = ActionChains(driver)
actions.send_keys('K')
actions.perform()
time.sleep(randint(15,50))
print("currently on site: " + driver.current_url)
count = count +1
if count == iterations:
break;
示例9: shake
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def shake(self):
""" Simulates a shake of the screen
By shaking, the current topology information will be updated in
browser's localstorage
"""
# shake the screen once to update localstorage
action = ActionChains(self._selenium.driver)
element = self._selenium.get_webelement('//body')
action.move_to_element_with_offset(element,0, 0).perform()
action.move_to_element_with_offset(element,200,200).perform()
action.click_and_hold(element).perform()
action.move_by_offset(1,0).perform()
action.move_by_offset(-1,0).perform()
action.release().perform()
self.refresh_canvas()
BuiltIn().log("Shaked the canvas once")
示例10: move_to
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def move_to(self,x=u'0',y=u'0',delay=u'1s',element=u'//canvas',mark_screen=False):
""" Moves the pointer to screen coodinate of the element
Default element is `canvas`
"""
action = ActionChains(self._selenium.driver)
action.move_to_element_with_offset(self._selenium.get_webelement(element), 0, 0).perform()
time.sleep(5)
action.move_to_element_with_offset(self._selenium.get_webelement(element), int(x),int(y)).perform()
time.sleep(DateTime.convert_time(delay))
if mark_screen:
BuiltIn().log("Marked to screen on (%d,%d)" % (x,y))
img_file = self.capture_screenshot(extra='_move')
img = cv2.imread(Common.get_result_path() + '/' + img_file)
cv2.drawMarker(img, (int(x),int(y)), color=(0,255,0), markerType=cv2.MARKER_CROSS, thickness=2)
cv2.imwrite(Common.get_result_path() + '/' + img_file,img)
BuiltIn().log('Moved the pointer to (%d,%d)' % (x,y))
示例11: click_on
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def click_on(self,point,element=u'//canvas',mark_screen=False):
""" Click on a screen coordinate of an element
Default element is `//cannvas`
"""
x,y = point
el = self._selenium.get_webelement(element)
action = ActionChains(self._selenium.driver)
action.move_to_element_with_offset(el,0,0).perform()
action.move_to_element_with_offset(el,x,y).perform()
if mark_screen:
BuiltIn().log("Marked to screen on (%d,%d)" % (x,y))
img_file = self.capture_screenshot(extra='_click')
img = cv2.imread(Common.get_result_path() + '/' + img_file)
cv2.drawMarker(img, (int(x),int(y)), color=(0,255,0), markerType=cv2.MARKER_CROSS, thickness=2)
cv2.imwrite(Common.get_result_path() + '/' + img_file,img)
action.click().perform()
self.wait_until_loaded()
BuiltIn().log("Clicked on element %s at (%d,%d)" % (element,x,y))
示例12: test_edit_item
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def test_edit_item(self):
self.login()
time.sleep(1)
try:
item = self.client.find_element_by_xpath("//span[text()='test item 1']")
item_body = 'test item 1'
except NoSuchElementException:
item = self.client.find_element_by_xpath("//span[text()='test item 2']")
item_body = 'test item 2'
hover_item = ActionChains(self.client).move_to_element(item)
hover_item.perform()
edit_button = self.client.find_element_by_class_name('edit-btn')
edit_button.click()
edit_item_input = self.client.find_element_by_id('edit-item-input')
edit_item_input.send_keys(' edited')
edit_item_input.send_keys(Keys.RETURN)
time.sleep(1)
self.assertIn('%s edited' % item_body, self.client.page_source)
示例13: perform_actions_3
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def perform_actions_3(self, actions, delay=0, pause=True):
action_chains = ActionChains(self.driver)
for key, flag in self.dir_keys.items():
if flag:
if key not in actions:
self.keyup(key)
else:
if key in actions:
self.keydown(key)
if pause:
action_chains.send_keys(Keys.F2)
for _ in range(delay):
action_chains.send_keys(Keys.F2)
action_chains.perform()
示例14: perform_actions_3_2
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def perform_actions_3_2(self, actions, delay=0, pause=True):
action_chains = ActionChains(self.driver)
for key, flag in self.dir_keys_2.items():
if flag:
if key not in actions:
self.keyup_2(key)
else:
if key in actions:
self.keydown_2(key)
if pause:
action_chains.send_keys(Keys.F2)
for _ in range(delay):
action_chains.send_keys(Keys.F2)
action_chains.perform()
示例15: move_to_element
# 需要導入模塊: from selenium.webdriver.common import action_chains [as 別名]
# 或者: from selenium.webdriver.common.action_chains import ActionChains [as 別名]
def move_to_element(self, element, offset=None):
"""
Moves the mouse to the middle of an element
:param element: CSS Selector or XPATH used to locate the element
:type element: str
:param offset: optional tuple of x/y offsets to offset mouse from center
:type offset: tuple
:return:
"""
elem = self.get_element(element)
actions = ActionChains(self)
if offset:
actions.move_to_element_with_offset(elem, *offset)
else:
actions.move_to_element(elem)
actions.perform()