Cucumber How to Hover over an element?
I have an element styled with a css hover.
I tried using this
page.execute_script(“$(‘#{selector}’).mouseover();”)
but does not work?
anyone开发者_开发百科 else encountered this problem using a css hover? Thanks!
Try this one:
page.evaluate_script("$('#{element_name}').trigger('mouseover')")
Here is step from my application
When /^I hover and click on "([^\"]*)"$/ do |selector|
page.driver.browser.execute_script %Q{
$("#{selector}").trigger("mouseenter").click();
}
end
Alternatively, you coul call the function that is bound to that event
I used .hover() and it worked. Thanks for the answers!
I ended up having to add a class 'hover' to the element
element {
&:hover, &.hover { //styles }
}
and trigger it in Cucumber by
page.execute_script(“$(‘#{selector}’).mouseover().addClass('hover');”)
精彩评论