2011-05-02 11 views
8

Sto cercando di attivare il mouse sull'evento usando move_to_element in ActionChains, Impossibile farlo funzionare. Qualsiasi aiuto è apprezzato. Grazie.Qualcuno ha usato ActionChains di Webdriver (collegamento Python)?

+0

Prova actor.py invece: https://gist.github.com/2036553 - permette di chiamare le azioni direttamente invece di memorizzarli, quindi chiamare 'eseguire'. –

risposta

7

Oggi mi sono divertito con ActionChain anche in Python e ho capito che il doppio clic non funziona solo clic. Allora, come è il tuo codice. Per fare qualsiasi cambio di azione devi eseguire 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() 
6
from selenium.webdriver.common.action_chains import ActionChains 

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

se si desidera selezionare qualsiasi valore,

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' deve essere solo una convenzione di denominazione scadente – User

0

mi è stato sempre un ActionChains non è definito errore finché ho importato actionchains da selenio. Poi sono stato in grado di utilizzare actions.move_to_element() e actions.click()

from selenium.webdriver.common.action_chains import ActionChains 
Problemi correlati