开发者

Cucumber How to Hover over an element?

开发者 https://www.devze.com 2023-03-29 00:48 出处:网络
I have an element styled with a css hover. I tried using this page.execute_script(“$(‘#{selector}’).mouseover();”)

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');”)
0

精彩评论

暂无评论...
验证码 换一张
取 消