2011-12-19 48 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