本文整理汇总了Python中selenium.webdriver.common.action_chains.ActionChains类的典型用法代码示例。如果您正苦于以下问题:Python ActionChains类的具体用法?Python ActionChains怎么用?Python ActionChains使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActionChains类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: goto_options_item
def goto_options_item(self, link):
"""click on a group management option link"""
if not link in self._links:
raise ValueError("invalid link name: '%s'", link)
base = self.owner.find_element(self.locators["base"])
# hover mouse over the group manager toolbar to expand it
actionProvider = ActionChains(self.owner._browser).move_to_element(base)
self.logger.debug("moving mouse over options dropdown")
actionProvider.perform()
# move the mouse to the correct link and click it
loc = self.locators[link]
e = self.owner.find_element(loc, base)
# moving to the element does not work in this case
# I think because the browser's popup window for the url
# blocks the element? either way, we can click the element
# just by having the options menu open.
# actionProvider = ActionChains(self.owner._browser)\
# .move_to_element(e)
# actionProvider.perform()
self.owner.wait_for_page_element_displayed(loc)
self.logger.debug("clicking drowdown menu option '%s': %s" % (link, loc))
e.click()
示例2: mouse_over
def mouse_over(self):
LOG.debug('Mouse over element %s' % str(self.locator))
self.scroll_into_view()
element = self.get_element()
chain = ActionChains(self.driver)
chain.move_to_element(element)
chain.perform()
示例3: test_copy_from_language
def test_copy_from_language(self):
self._login()
self.driver.get('%s/it/?%s' % (self.live_server_url, get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')))
# check if there are no plugins in italian version of the page
italian_plugins = self.page.placeholders.all()[0].get_plugins_list('it')
self.assertEqual(len(italian_plugins), 0)
build_button = self.driver.find_element_by_css_selector('.cms-toolbar-item-cms-mode-switcher a[href="?%s"]' % get_cms_setting('CMS_TOOLBAR_URL__BUILD'))
build_button.click()
submenu = self.driver.find_element_by_css_selector('.cms-dragbar .cms-submenu')
hov = ActionChains(self.driver).move_to_element(submenu)
hov.perform()
submenu_link_selector = '.cms-submenu-item a[data-rel="copy-lang"][data-language="en"]'
WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, submenu_link_selector)))
copy_from_english = self.driver.find_element_by_css_selector(submenu_link_selector)
copy_from_english.click()
# Done, check if the text plugin was copied and it is only one
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '.cms-draggable:nth-child(1)')))
italian_plugins = self.page.placeholders.all()[0].get_plugins_list('it')
self.assertEqual(len(italian_plugins), 1)
plugin_instance = italian_plugins[0].get_plugin_instance()[0]
self.assertEqual(plugin_instance.body, 'test')
示例4: hover
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()
示例5: _drag_page_el_2_thing
def _drag_page_el_2_thing(step, element_name, pick, find_pattern):
src = get_visible_page_element(element_name)
target = _get_visible_element(finder_function, pick, find_pattern)
action_chain = ActionChains(world.browser.driver)
action_chain.drag_and_drop(src, target)
action_chain.perform()
示例6: test_create_delete_user
def test_create_delete_user(self):
user_name = "test_user_ui_%s" % str(random.randint(1,100))
driver = self.driver
driver.maximize_window()
driver.get(self.base_url + "/")
driver.find_element_by_name("username").send_keys(config.username)
driver.find_element_by_name("password").send_keys(config.password)
driver.find_element_by_css_selector("input.loginSubmit").click()
Move = ActionChains(driver).move_to_element(driver.find_element_by_link_text("Settings"))
Move.perform()
driver.find_element_by_link_text("Users").click()
#Creation
driver.find_element_by_link_text("Create User").click()
driver.find_element_by_id("name").send_keys(user_name)
driver.find_element_by_id("email").send_keys("%[email protected]"
% user_name)
driver.find_element_by_id("password").send_keys("password")
driver.find_element_by_id("confirm_password").send_keys("password")
driver.find_element(By.XPATH, "//input[@id='select_tenant_id']").click()
driver.find_element_by_link_text("openstack").click()
driver.find_element(By.XPATH, "//input[@id='select_role_id']").click()
driver.find_element_by_link_text("Member").click()
driver.find_element_by_name("_action_save").click()
time.sleep(3)
self.assertTrue(driver.find_element_by_xpath(
"//tbody/tr/td[text()='%s']" % user_name).is_displayed())
#deletion
driver.find_element_by_xpath(
"//*[text()='%s']/../td/input[@type='checkbox']"
% user_name).click()
driver.find_element_by_name("_action_delete").click()
driver.find_element_by_id("btn-confirm").click()
time.sleep(1)
self.assertFalse(self.is_element_present(
By.XPATH,"//tbody/tr/td[text()='%s']" % user_name))
示例7: test_o_511_links_roadway_weather_forecasts
def test_o_511_links_roadway_weather_forecasts(self, windows_handles=None):
print '\n' + "Verifying: Links -> National Roadway Weather Forecasts"
driver = self.driver
driver.maximize_window()
actions = ActionChains(driver)
menu = driver.find_element_by_xpath("//*[contains(text(), 'Links')]")
actions.move_to_element(menu).perform()
time.sleep(3)
contactIDLink = driver.find_element_by_xpath("//*[contains(text(), 'Roadway Weather Forecasts')]")
actions.move_to_element(contactIDLink).click().perform()
driver.switch_to.window(driver.window_handles[-1])
roadwayWeatherPageVerification = WebDriverWait(driver, 20).until(EC.presence_of_element_located(
(By.XPATH, "//*[contains(text(), 'National Weather Service - NWS Pocatello')]")))
roadwayWeatherTitle = driver.title
assert roadwayWeatherTitle == 'National Weather Service - NWS Pocatello', 'The National Roadway Weather Forecasts page link did not load properly'
示例8: test_p_511_links_I15_construction
def test_p_511_links_I15_construction(self, windows_handles=None):
print '\n' + "Verifying: Links -> I15 Construction"
driver = self.driver
driver.maximize_window()
actions = ActionChains(driver)
menu = driver.find_element_by_xpath("//*[contains(text(), 'Links')]")
actions.move_to_element(menu).perform()
time.sleep(3)
contactIDLink = driver.find_element_by_xpath("//*[contains(text(), 'I-15 Construction')]")
actions.move_to_element(contactIDLink).click().perform()
driver.switch_to.window(driver.window_handles[-1])
i15PageVerification = WebDriverWait(driver, 20).until(EC.presence_of_element_located(
(By.XPATH, "//*[contains(text(), 'I-15 Construction | Idaho Transportation Department')]")))
i5Title = driver.title
assert i5Title == 'I-15 Construction | Idaho Transportation Department', 'The I15 Construction page link did not load properly'
示例9: test_f_511_tourist_info_rest_areas
def test_f_511_tourist_info_rest_areas(self, window_handles=None):
### 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
### RELATIVE X-PATH
### 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
print '\n' + "Verifying: Tourist Info -> Rest Areas"
driver = self.driver
driver.maximize_window
actions = ActionChains(driver)
menu = driver.find_element_by_xpath("//*[contains(text(), 'Tourist Info')]")
actions.move_to_element(menu).perform()
time.sleep(3)
restAreasLink = driver.find_element_by_xpath("//*[@id='ddsubmenu2']/li[2]/a")
actions.move_to_element(restAreasLink).click().perform()
driver.switch_to.window(driver.window_handles[-1])
restAreasTitle = driver.title
assert restAreasTitle == 'Road Maintenance | Idaho Transportation Department', 'The Rest Areas page link did not work correctly'
示例10: test_n_511_links_national_weather_service
def test_n_511_links_national_weather_service(self, windows_handles=None):
print '\n' + "Verifying: Links -> National Weather Service"
driver = self.driver
driver.maximize_window()
actions = ActionChains(driver)
menu = driver.find_element_by_xpath("//*[contains(text(), 'Links')]")
actions.move_to_element(menu).perform()
time.sleep(3)
contactIDLink = driver.find_element_by_xpath("//*[contains(text(), 'National Weather Service')]")
actions.move_to_element(contactIDLink).click().perform()
driver.switch_to.window(driver.window_handles[-1])
nationalWeatherPageVerification = WebDriverWait(driver, 20).until(EC.presence_of_element_located(
(By.XPATH, "//*[contains(text(), 'Western Region Headquarters')]")))
nationalWeatherServiceTitle = driver.title
assert nationalWeatherServiceTitle == 'Western Region Headquarters', 'The National Weather Service page link did not load properly'
示例11: test_filter_tenants
def test_filter_tenants(self):
driver = self.driver
driver.maximize_window()
driver.get(self.base_url + "/")
driver.find_element_by_name("username").send_keys(config.username)
driver.find_element_by_name("password").send_keys(config.password)
driver.find_element_by_css_selector("input.loginSubmit").click()
Move = ActionChains(driver).move_to_element(driver.find_element_by_link_text("Settings"))
Move.perform()
driver.find_element_by_link_text("Tenants").click()
driver.find_element_by_link_text("Create Tenant").click()
driver.find_element_by_id("name").send_keys("Test_tenant")
driver.find_element_by_id("description").send_keys("Test_description")
driver.find_element_by_id("enabled").click()
driver.find_element_by_name("_action_save").click()
driver.find_element_by_xpath("//div/input[@type='text']").send_keys("Test_tenant")
time.sleep(1)
self.assertTrue(driver.find_element_by_xpath("//tbody/tr/td[text()='Test_tenant']").is_displayed())
self.assertFalse(driver.find_element_by_xpath("//tbody/tr/td[text()='services']").is_displayed())
_all_elem = len(driver.find_elements_by_xpath("//tbody/tr"))
_elem_disp = len(driver.find_elements_by_xpath("//tbody/tr[@style='display: none;']"))
self.assertTrue(_all_elem - _elem_disp==int(driver.find_elements_by_xpath("//div/label")[1].text))
elements = driver.find_elements_by_xpath("//tbody/tr/td/a")
time.sleep(1)
for i in elements:
if i.is_displayed() != 0:
i.click()
break
time.sleep(5)
driver.find_element_by_xpath('//*[@id="delete"]/span/div').click()
driver.find_element_by_xpath('//*[@id="btn-confirm"]/span').click()
#alert = driver.switch_to_alert()
#alert.accept()
self.assertFalse(self.is_element_present(By.XPATH, "//tbody/tr/td[text()='Test_tenant']"))
示例12: init_browser
def init_browser(self):
if True:# self.browser_type == "firefox".upper():
# adding adblock to the system
#binary = FirefoxBinary(r"Drivers/firefox/bin/firefox.exe")
# firefox_profile = FirefoxProfile()
# if self.adblock is True:
# adblock_path = os.path.abspath('Drivers/adblock_plus-2.7.3-sm+tb+fx+an.xpi')
# firefox_profile.add_extension(extension=adblock_path)
binary = FirefoxBinary(self.browser_path)
self.browser = Firefox(firefox_binary=binary)
# muting the browser
action = ActionChains(self.browser)
action.send_keys(Keys.CONTROL + "m")
action.perform()
elif self.browser_type == "Edge".upper():
edge_driver = "Drivers/EdgeDriver"
os.environ["webdriver.edge.driver"] = edge_driver
self.browser = Edge(edge_driver)
elif self.browser_type == "PHANTOMJS":
user_agent = (
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36"
)
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = user_agent
self.browser = PhantomJS("Drivers/phantomjs.exe", desired_capabilities=dcap)
示例13: put_element_on_grid
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
示例14: move_to_element
def move_to_element(loc, **kwargs):
"""
Moves to an element.
Args:
loc: A locator, expects either a string, WebElement, tuple.
Returns: Returns the element it was moved to to enable chaining.
"""
brand = "//div[@id='page_header_div']//div[contains(@class, 'brand')]"
wait_for_ajax()
el = element(loc, **kwargs)
if el.tag_name == "option":
# Instead of option, let's move on its parent <select> if possible
parent = element("..", root=el)
if parent.tag_name == "select":
move_to_element(parent)
return el
move_to = ActionChains(browser()).move_to_element(el)
try:
move_to.perform()
except MoveTargetOutOfBoundsException:
# ff workaround
execute_script("arguments[0].scrollIntoView();", el)
if elements(brand) and not is_displayed(brand):
# If it does it badly that it moves whole page, this moves it back
try:
execute_script("arguments[0].scrollIntoView();", element(brand))
except MoveTargetOutOfBoundsException:
pass
try:
move_to.perform()
except MoveTargetOutOfBoundsException: # This has become desperate now.
raise exceptions.CannotScrollException(
"Despite all the workarounds, scrolling to `{}` was unsuccessful.".format(loc))
return el
示例15: test_t_511_links_transporting_a_boat
def test_t_511_links_transporting_a_boat(self, windows_handles=None):
print '\n' + "Verifying: Links -> Transporting a Boat"
driver = self.driver
driver.maximize_window()
actions = ActionChains(driver)
menu = driver.find_element_by_xpath("//*[contains(text(), 'Links')]")
actions.move_to_element(menu).perform()
time.sleep(3)
contactIDLink = driver.find_element_by_xpath("//*[contains(text(), 'Transporting a Boat')]")
actions.move_to_element(contactIDLink).click().perform()
driver.switch_to.window(driver.window_handles[-1])
transABoatPageVerification = WebDriverWait(driver, 20).until(EC.presence_of_element_located(
(By.XPATH, "//*[contains(text(), 'Pacific States Marine Fisheries Commission')]")))
transBoatTitle = driver.title
assert transBoatTitle == 'Pacific States Marine Fisheries Commission', 'The Transporting a Boat page link did not load properly'