Ruby Mouse Over is not long enough, may need a delay of some sort

為{幸葍}努か 提交于 2019-12-12 02:16:04

问题


Hope you all are well. This is my first post.

I am trying to write a script in Ruby using Cucumber and the Selenium 2 framework.

I am trying to find out how to click on any given link on a hover based component.

The sainsbury's website http://www.sainsburys-live-well-for-less.co.uk/ is the perfect example.

If you select the first link i.e. Recipes and Insprirations followed by Lets get backing then you are redirected to a new page.

I want to do this through a script.

Currently I am having issues displaying the overlay components which appears when placing the mouse cursor over the Recipes & Inspiration button.

I am able to make the hover over component appear using the @driver.mouse.move_to ele function. The next step would be to look through the collection, find the element and click on it but the problem is that there are too many steps involved and by the time I even get to check the number of items in the hidden panel, the panel dissapears.

I have also tried using the Ruby Builder but had no luck. If someone can help me out and use the sainsbury website as an example then it would help out greatly.

Thanks in advance.


回答1:


Well you can use the sleep command followed by the number of seconds that you want selenium to wait before executing the next step. For example..:

sleep 2

Will wait for 2 seconds before moving onto the next line of your script.

Also check this answer for clicking hidden menus..

Okay. Because I remember how it is when you start. There you go. I've done this for you..

require "selenium-webdriver"          
Selenium::WebDriver::Firefox     
driver = Selenium::WebDriver.for :firefox

driver.navigate.to('http://www.sainsburys-live-well-for-less.co.uk/')   

menu = driver.find_element(:xpath, "//div[@id='recipes-inspiration-menu']")
submenu = driver.find_element(:xpath, "//li[@class='first first-child  children']")

driver.action.move_to(menu).click(submenu).perform

driver.find_element(:xpath, "//a[@title='Let's Get Baking']").click

As I said, download and install Firebug it would help you a lot..



来源:https://stackoverflow.com/questions/11564716/ruby-mouse-over-is-not-long-enough-may-need-a-delay-of-some-sort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!