有没有人使用过ActionChains的Webdriver(python绑定)?

dmp*_*dmp 11 python webdriver

我试图使用ActionChains中的move_to_element触发鼠标悬停事件,无法使其正常工作.任何帮助表示赞赏.谢谢.

Raj*_*nka 11

from selenium.webdriver.common.action_chains import ActionChains

ActionChains(drivers).move_to_element(drivers.find_element_by_id('element_id')).click().perform()
Run Code Online (Sandbox Code Playgroud)

如果你想选择任何值,

 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()
Run Code Online (Sandbox Code Playgroud)


Bob*_*ans 8

我今天也在使用python中的ActionChains,并且意识到double_click只能点击.那么你的代码是什么样的.要执行任何操作更改,您必须运行执行.

 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()
Run Code Online (Sandbox Code Playgroud)


Mic*_*ter 5

在我从 selenium 导入 actionchains 之前,我收到了一个 ActionChains is not defined 错误。然后我就可以使用 actions.move_to_element() 和 actions.click()

from selenium.webdriver.common.action_chains import ActionChains
Run Code Online (Sandbox Code Playgroud)