2011-05-02 9 views
8

Im tratando de desencadenar el mouse sobre evento usando move_to_element en ActionChains, no se pudo hacer funcionar. Cualquier ayuda es apreciada. Gracias.¿Alguien ha usado ActionChains of Webdriver (enlace de python)?

+0

Trate actor.py lugar: https://gist.github.com/2036553 - que le permite llamar a las acciones directamente en lugar de almacenarlos, luego llamar a 'ejecutar'. –

Respuesta

7

He estado jugando con ActionChains en Python hoy también y me di cuenta de que el double_click no solo funciona. Entonces, ¿cómo se ve tu código? Para hacer cualquier cambio de acción, debe ejecutar ejecutar.

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() 
6
from selenium.webdriver.common.action_chains import ActionChains 

ActionChains(drivers).move_to_element(drivers.find_element_by_id('element_id')).click().perform() 

si desea seleccionar cualquier valor,

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() 
+0

'drivers' debe ser una convención de nomenclatura pobre – User

0

que estaba recibiendo un ActionChains no está definido error hasta Importé actionchains de selenio. Entonces yo era capaz de utilizar actions.move_to_element() y actions.click()

from selenium.webdriver.common.action_chains import ActionChains 
Cuestiones relacionadas