如何使用水豚和硒悬停在图像上

时间:2022-11-05 08:39:52

Ive been trying to write an automation test to hover over an image using just capybara and selenium. Once i can get it to hover over the image i would like to check that the image has changed ie through the background image using the css. After some research some people have been saying that the trigger method doesnt work with selenium so ive been trying different stuff like:

我一直试图编写一个自动化测试,只使用水豚和硒悬停在图像上。一旦我可以将它悬停在图像上,我想检查图像是否已经改变,即使用css通过背景图像。经过一些研究,一些人一直在说触发方法不适用于硒,所以我一直尝试不同的东西,如:

hover = driver.find_element(:css => "element")
  driver.move_to.(hover).perform

featured_promo = page.find(:xpath, '//*[@id = "btnCalendar"]')
  featured_promo.native.hover()

Both of these have not worked.

这两个都没有奏效。

Any help or suggestions would be greatly appreciated.

任何帮助或建议将不胜感激。

2 个解决方案

#1


2  

Try this..

driver.mouse.move_to(hover)

#2


1  

Referring to this page: http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/ActionBuilder.html
Your code should look probably like below:

参考此页面:http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/ActionBuilder.html您的代码应如下所示:

element = driver.find_element(...)
driver.action.move_to(element).perform

#1


2  

Try this..

driver.mouse.move_to(hover)

#2


1  

Referring to this page: http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/ActionBuilder.html
Your code should look probably like below:

参考此页面:http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/ActionBuilder.html您的代码应如下所示:

element = driver.find_element(...)
driver.action.move_to(element).perform