angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

How to similulate mouse over events such as click a link on mouse over #159

Closed vishalshivnath closed 11 years ago

vishalshivnath commented 11 years ago

I have a main menu. If i click on main menu it opens sub menu on mouse over. This sub menu us hidden element. Protractor is clicking on the main menu but not cant simulate the action on mouse over event

Tried below four ways to simulate mouse hover action

  1. driver.executeScript("document.getElementById('dBysuspect typeLabel')[0].mouseover();");
  2. driver.executeScript("return ptor.By.id('dBysuspect typeLabel').hover();");
  3. reviewProviderPage.reviewProvidersBySuspect.hover();
  4. driver.executeScript("reviewProviderPage.reviewProvidersBySuspect.hover():");

Got below error. Message: Type Error: Object [object Object] has no method 'hover'

juliemr commented 11 years ago

You'll need to use an action sequence for hovering:

ptor.actions().
    mouseMove(ptor.findElement(protractor.B.id('foo'))).
    perform();

See https://code.google.com/p/selenium/source/browse/javascript/webdriver/actionsequence.js for the full actions API.

vishalshivnath commented 11 years ago

Thanks it working, hence closing this ticket

mgol commented 10 years ago

This doesn't work for me. :/ For the following code:

browser.actions().mouseMove($('cbn-slider')).perform();

I get an error:

   Message:
     TypeError: Object [object Object] has no method 'toWireValue'
   Stacktrace:
     TypeError: Object [object Object] has no method 'toWireValue'
    at null.<anonymous> (*/test/e2e/e2e-spec.defs.js:57:31)
    at */node_modules/protractor/jasminewd/index.js:54:12
    at wrapper [as _onTimeout] (timers.js:252:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
==== async task ====
    at null.<anonymous> (*/node_modules/protractor/jasminewd/index.js:53:12)
    at null.<anonymous> (*/node_modules/protractor/node_modules/minijasminenode/lib/async-callback.js:45:37)
mgol commented 10 years ago

OK, I found the answer here: https://github.com/angular/protractor/issues/123#issuecomment-32619455 Instead of $('cbn-slider') I need to write $('cbn-slider').find(). Seems a little unintuitive and documentation here is sparse at best.

elgalu commented 10 years ago

Hey @mzgol thanks for the .find() update :+1:

ffesseler commented 10 years ago

Yep, was also stuck until I've stuble upon this issue.

I would suggest adding something about this in the doc. If you tell me where it's best to put it, I'm keen to do a PR

vishaljoshi commented 10 years ago

Hi, I am having a drop down menu which shows up on mouse over and hides on mouse out, The below code fire a mouse out event instantly so the menu hides immediately. So all you can see is a flicker on the screen. Any help would be appreciated.

ptor.actions(). mouseMove(ptor.findElement(protractor.By.id('id_element'))).perform();

ghost commented 10 years ago

@vishalshivnath I have recently come across the same issue as you, so created this ticket:

https://github.com/angular/protractor/issues/1034

Rajgowtham commented 10 years ago

HI,

I am new to selenium, i working with menu, need to click sub menu using selenium webdriver, could anyone help with tat :(

aricearice commented 10 years ago

I'm using the action sequence that @juliemr suggested in order to perform a hover over a button. It's working for me in FireFox and Chrome, but it's throwing the following error when I run my tests in Safari. Any ideas how to work around this? I've been searching the web for a solution, but the ones I've found so far are not working out for me when I try them in elementexplorer..

Example page I've looked into: https://code.google.com/p/selenium/issues/detail?id=2067 Perhaps I need a bit of time to grasp the code in #57 and #60, but I'm also wondering if this issue is being looked at, whether by the Protractor team or the WebDriver team..

UnknownError: Unknown command: mouseMoveTo (WARNING: The server did not provide any stacktrace information)
[safari #3] Command duration or timeout: 4 milliseconds
[safari #3] Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:32:38'
[safari #3] System info: os.name: 'Windows Server 2008 R2', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_60'
[safari #3] Session ID: null
[safari #3] Driver info: org.openqa.selenium.safari.SafariDriver
[safari #3] Capabilities [{platform=WINDOWS, javascriptEnabled=true, cssSelectorsEnabled=true, secureSsl=true, browserName=safari, takesScreenshot=true, version=5.1.7}]
[safari #3]    Stacktrace:
[safari #3]      UnknownError: Unknown command: mouseMoveTo (WARNING: The server did not provide any stacktrace information)
[safari #3] Command duration or timeout: 4 milliseconds
[safari #3] Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:32:38'
[safari #3] System info: os.name: 'Windows Server 2008 R2', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_60'
[safari #3] Session ID: null
[safari #3] Driver info: org.openqa.selenium.safari.SafariDriver
[safari #3] Capabilities [{platform=WINDOWS, javascriptEnabled=true, cssSelectorsEnabled=true, secureSsl=true, browserName=safari, takesScreenshot=true, version=5.1.7}]
[safari #3] ==== async task ====
[safari #3] mouseMove
[safari #3]     at Array.forEach (native)
[safari #3] ==== async task ====
[safari #3] ActionSequence.perform
[safari #3]     at hover (maxbase.js:149:7)
[safari #3]     at showLoginMenu (maxhome.js:94:12)
[safari #3]     at logout (maxhome.js:8:14)
[safari #3]     at null.<anonymous> (home.test.js:93:14)
[safari #3] ==== async task ====
[safari #3] Asynchronous test function: it()
[safari #3] Error
[safari #3]     at testSigningOut (home.test.js:91:2)
[safari #3]     at null.<anonymous> (p1.spec.js:30:14)
[safari #3]     at Object.<anonymous> (p1.spec.js:7:1)
abhagupta commented 9 years ago

@aricearice - Were you able to find out the solution for your problem. I have stumbled upon same issue in Safari.

bmsoko commented 9 years ago

Same here, I've stepped on this issue too... Did anyone find a workaround?

Thanks

daluu commented 9 years ago

For Safari issue, see also #1526. As mentioned by @aricearice, comments 57 & 60 in the referenced Selenium issue on Google Code should have the workaround.

Basically, the workaround is to execute JS code in the browser to simulate mouse events (rather than use native events which SafariDriver does not yet support). Javascript based mouse over or hover, something you can search online about to get a better understanding of it (as well as more code samples), if comments 57 & 60 are not easy to decipher.

Also, if one needs javascript based drag & drop, see #1526, where I mention another reference to JS code snippet for that.

Also, if one wants mouse click instead of hover or drag & drop, can do that too. I have a blog post about all these JS simulations here:

https://autumnator.wordpress.com/2013/02/09/javascript-is-your-ally-for-selenium-webdriver/

csanthoshi commented 8 years ago

I am unable to hover over an element( hyper link). I observed that when I placed my physical mouse pointer on the browser( launched through automation ) the element did not hovered but once I moved the physical pointer outside of the browser as soon as run gets triggered, the hovering action is passing successfully. I am running the script in chrome browser using protractor

The code snippet that I used is

browser.sleep( 8000 ); var ele = element( by.xpath( '//tf-infobox//[normalize-space(.)="Error 1"]/following-sibling:://a' ) ); browser.actions().mouseMove( ele ).perform(); browser.sleep( 5000 );

Additional Info: I can able to click the element but hovering is not possible. Chrome-driver version: 2.21

Can someone help me out to solve my problem.

Thanks!

latobibor commented 8 years ago

I second @csanthoshi . Is there a way to fire it only from script without the interference of the physical mouse?

amod-thakur commented 5 years ago

I sort of discovered a workaround to the mouse hover issue on chrome by accident. If we chain the mouseMove() method twice , it works.

Code that doesn't work on chrome: browser.actions.mouseMove(element).click().perform();

Code with workaround(which works) browser.actions.mouseMove(element).mouseMove(element).click().perform();

vijayjdk commented 5 years ago

You'll need to use an action sequence for hovering:

ptor.actions().
    mouseMove(ptor.findElement(protractor.B.id('foo'))).
    perform();

See https://code.google.com/p/selenium/source/browse/javascript/webdriver/actionsequence.js for the full actions API.

Hi @juliemr Above code is working fine in chrome. But i need to run my script for firefox and this code is failing in firefox browser. Below is the error i am facing while executing same code on firefox

**

UnknownCommandError: POST /session/24e1787f-7623-4690-b9a9-92ba32c552e1/moveto did not match a known command

** Please help me to solve this issue

viniciusrad commented 1 year ago

almost 10 years later I ran into the same situation. And I ended up creating a very simple solution

A function at (mouseenter)="myFunc($event)" in element and then

myFunc(event: any){ event.target.click() }

Done, no pain