wiki:webtest/question_3

Version 1 (modified by chenyang, 12 years ago) (diff)

--

论坛版块页的发帖按钮,注册了onmouse事件,当鼠标移入的时候,会弹出发帖类型菜单供选择。如下图:

如何编写脚本来实现呢?
selenium API中提供了ActionChains对象用来处理注册事件,首先要实例化一个ActionChains对象,然后调用该对象的move_to_element方法将mouse移动指定的元素上
示例代码如下:

	......
	#找到发帖按钮
	btn = driver.find_element_by_xpath("//div[@id='content']/div[@class='forumBar cle']/div[@class='btn_post']")	
	btn.location_once_scrolled_into_view
	chains = ActionChains(driver)		
	#鼠标移到发帖按钮
	chains.move_to_element(btn).perform()
	#点击发投票帖
	vote_btn = driver.find_element_by_xpath("//div[@id='content']/div[@class='forumBar cle']/div[@class='btn_post']/ul/li[@class='vote']")	
	vote_btn.click()
	......

注意,别忘了要调用perform()方法,来执行元素上注册的事件

Attachments