2011-05-02 29 views
8

Im cố gắng kích hoạt chuột qua sự kiện bằng cách sử dụng move_to_element trong ActionChains, Không thể làm cho nó hoạt động. Bất kỳ trợ giúp được đánh giá cao. Cảm ơn.Có ai sử dụng ActionChains của Webdriver (python binding) không?

+0

Hãy thử actor.py thay vì: https://gist.github.com/2036553 - nó cho phép bạn gọi các hành động trực tiếp thay vì lưu trữ chúng, sau đó gọi 'thực hiện'. –

Trả lời

7

Tôi cũng đang đùa giỡn với ActionChains trong python hôm nay và nhận ra rằng double_click không hoạt động chỉ khi nhấp. Vì vậy, mã của bạn trông như thế nào. Để thực hiện bất kỳ thay đổi hành động nào bạn phải thực hiện.

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

nếu bạn muốn chọn bất kỳ giá trị,

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

'trình điều khiển' phải chỉ là quy ước đặt tên kém – User

0

Tôi đã nhận được một ActionChains không được định nghĩa lỗi cho đến khi tôi nhập khẩu actionchains từ selen. Sau đó, tôi đã có thể sử dụng actions.move_to_element() và actions.click()

from selenium.webdriver.common.action_chains import ActionChains 
Các vấn đề liên quan