2011-10-16 50 views
2

我使用的类似结构:水豚,硒具有隐藏或显示交互:无CSS属性

<div class="edit" style="visibility: hidden;"> 
    <a href="some_path" id="edit_item">Edit</a> 
</div> 

然后我将鼠标悬停鼠标这个元素变得可见,但我有困难的相互作用与测试此操作(使用黄瓜,水豚,硒)。

我得到一个错误

Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotDisplayedError)

我试图用Element.trigger(event)与鼠标悬停,但它不能在硒... 我怎么能与此元素进行交互工作?

回答

4

我解决了使用execute_script从水豚这个问题:

When /^I hover element "([^""]*)"(?: within "([^""]*)")?$/ do |id,selector| 
    with_scope(selector) do 
    page.execute_script("$('#{id}').mouseover();") 
    end 
end 

When /^I click in hide element "([^""]*)"(?: within "([^""]*)")?$/ do |id,selector| 
    with_scope(selector) do 
    page.execute_script("$('#{id}').click();") 
    end 
end 

但这种方法不能与CSS的工作 - 显示:无;

+0

请注意,'with_scope'对'execute_script'没有影响。 –