有人使用过Webdriver的ActionChains(Python绑定)吗?
我想用ActionChains里的move_to_element来触发鼠标悬停事件,但一直没能成功。希望能得到一些帮助。谢谢!
3 个回答
5
我之前遇到了一个错误,提示“ActionChains没有定义”,直到我从selenium库中导入了actionchains。之后我就可以使用actions.move_to_element()和actions.click()这些功能了。
from selenium.webdriver.common.action_chains import ActionChains
8
今天我在玩Python里的ActionChains,发现双击功能不太好使,只有单击能正常工作。那么你的代码是怎样的呢?要执行任何动作,你必须运行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()
13
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(drivers).move_to_element(drivers.find_element_by_id('element_id')).click().perform()
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()
如果你想选择任何一个值,