2011-12-19 104 views
4

我正在测试的应用程序最初隐藏了一些元素。水豚硒驱动程序,悬停元素

.thread_options{ 
    display: none; 
} 
.btn_thread_options:hover .thread_options{ 
    display: inline; 
} 

当你将鼠标悬停在.btn_thread_options元素,将显示一些链接,我想水豚点击:徘徊在一个单独的元素时,他们将通过CSS显示。尝试点击这些不使用click_link "Send Response"做任何事情给我的错误:

Failure/Error: click_link("Send Response") 
Selenium::WebDriver::Error::ElementNotVisibleError: 
    Element is not currently visible and so may not be interacted with 

尝试使用一下它的其他方面一样

page.execute_script("$('.btn_thread_options').trigger('mouseover')") 

不工作,要么(相同的结果)。

也没有点击的项目先行先试,迫使它被鼠标滑过:

page.find(".btn_thread_options").click 

有没有什么办法让这个才能正常工作?

+0

你需要显示:无?或者将不透明度设置为0就足够了?如果没有,那么在删除之前,先点击jquery show(),然后隐藏()。 – Gazler 2011-12-19 20:34:35

+0

我不认为'opacity:0'真的会起作用,因为隐藏的元素会提交表单,我不希望人们意外地点击看起来像是空白的东西,最终提交他们不想要的东西。现在我的解决方法就是在mouseover和mouseout上隐藏/显示jquery,就像你提到的那样......但如果我可以将它保存在css中,它会很好:p – nzifnab 2011-12-19 21:05:39

回答

6

这一直是added到水豚:

find(:css, "#menu").hover 
+0

很高兴知道!尽管你从2年前开始琢磨这个问题,但我仍然会发现它对未来有用:) – nzifnab 2013-11-18 21:16:52

+0

比通过执行js来伪装它更好!谢谢! – 2014-01-27 23:54:17

3

您可以尝试直接显示元素,而不是直接显示元素。

page.execute_script("$('.thread_options').css('display','inline')") 

也可能调查ignore_hidden_elements的设置。它默认为false,但也许你已经设置为true。或者,而不是显示无,请将页边距设置为较大的负值。

/* Move the element off the screen */ 
.thread_options{ 
    margin: -9999px 0 -9999px 0; 
} 
/* Set the desired display margins 
.btn_thread_options:hover .thread_options{ 
    margin: 10px 0 10px 0; 
} 
+0

我喜欢这个,因为它对我很有用,运行execute_script wth css'display','block' – JohnMerlino 2012-01-17 21:21:31

+1

我对这个答案并不满意,因为它并不真正模仿用户的行为......但这是我唯一能够正确工作的东西。其他解决方案会周期性失败。但我会接受它,因为我没有更好的东西:p – nzifnab 2012-01-19 20:27:24

1

我发现了一种使用Capybara + Selenium驱动程序模拟“鼠标悬停”的方法。此代码为我工作:

module Capybara 
    module Node 
    class Element 
     def hover 
     @session.driver.browser.action.move_to(self.native).perform 
     end 
    end 
    end 
end