Im trying to trigger mouse over event using move_to_element in ActionChains, Couldn't get it working. Any help is ap开发者_如何学编程preciated. Thanks.
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(drivers).move_to_element(drivers.find_element_by_id('element_id')).click().perform()
if you want to select any value,
menu1 = drivers.find_element_by_xpath('html/path/of/select/box')
sub_menu0 = drivers.find_element_by_xpath('html/path/of/selected/option')
clickon = drivers.find_element_by_xpath(path/of/option/where/you/want/to/click)
action = ActionChains(drivers)
action.move_to_element(menu1)
action.move_to_element(sub_menu0)
action.click(clickon)
action.perform()
I've been toying with ActionChains in python today as well and realized that the double_click doesn't work only click. So what's your code look like. To do any action change you have to run perform.
def setUp(self):
self.webdriver = webdriver.Ie()
self.mouse = webdriver.ActionChains(self.webdriver)
self.webdriver.get("http://foo")
def test_webdriver(self):
mouse = self.mouse
wd = self.webdriver
wd.implicitly_wait(10)
element = wd.find_element_by_xpath("//div[@title='Create Page']")
mouse.move_to_element(element).perform()
I was getting an ActionChains is not defined error until i imported actionchains from selenium. Then I was able to use actions.move_to_element() and actions.click()
from selenium.webdriver.common.action_chains import ActionChains
精彩评论