Ruby Mouse Over还不够长,可能需要某种延迟 [英] Ruby Mouse Over is not long enough, may need a delay of some sort

查看:133
本文介绍了Ruby Mouse Over还不够长,可能需要某种延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望大家一切都好.这是我的第一篇文章.

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

我正在尝试使用Cucumber和Selenium 2框架在Ruby中编写脚本.

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.

塞恩斯伯里的网站 http://www.sainsburys-live-well- for-less.co.uk/是一个很好的例子.

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

如果您选择第一个链接(即食谱和Insprirations,然后再让Lets得到支持),则会将您重定向到新页面.

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.

我可以使用@ driver.mouse.move_to ele函数使悬停组件出现.下一步是浏览集合,找到元素并单击它,但是问题是涉及的步骤太多了,到我什至要检查隐藏面板中的项目数时,面板才会消失.

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.

我也尝试过使用Ruby Builder,但是没有运气.如果有人可以帮助我并以sainsbury网站为例,那将大有帮助.

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.

谢谢.

推荐答案

好吧,您可以使用sleep命令,后跟希望硒执行下一步之前要等待的秒数.例如..:

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

将等待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

正如我所说,下载并安装Firebug会对您有很大帮助.

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

这篇关于Ruby Mouse Over还不够长,可能需要某种延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆