3

I am using selenium (C#) with Grid to test web application. But I get unexpected results when the physical mouse is over the browser window.

Issue details
same question on stackoverflow.

I would like to move the physical mouse outside of browser window. I am not sure how to achieve it. I am using selenium grid to run tests on remote machines, so I would require something that would work over the Grid.

1

3 Answers 3

1

Selenium only works with a browser-driver. So you cannot move outside the working area, i.e. your browser.

You can use java method Actions to perform similar kind of tasks. If you have the coordinate where to click, you can try this.

Actions builder = new Actions(driver);   
builder.moveToElement(element, X, Y).click().build().perform();

Hope this helps.

2
  • 1
    Won't element still need to be inside the browser window? Mar 29, 2017 at 11:49
  • I have already tried this, it did not work. My issue is with the physical mouse pointer. Selenium will not work on that.
    – H.D.
    Mar 29, 2017 at 18:31
0

use java robot class or autoIT to move mouse. since you are using selenium grid you need to consider about screen resolution of multiple monitors.

both use screen coordinates to move mouse. you can use if commands inside the code to check the screen resolution and move mouse to relevant location. ex: if(resolutions is this) move to -> x1,y1 else (....) move to -> x2,y2

I hope this would work :)

3
  • 1
    I am still not sure how I can use it over selenium grid. How can I execute this piece of code remotely with grid?
    – H.D.
    Mar 29, 2017 at 18:29
  • add this in to ur test script so it will execute via selenium grid. Selenium grid distributes then execution into multiple machines, but it will execute your test script code. In the test script code call a method or a class to do this.
    – Suyama
    Apr 2, 2017 at 18:17
  • 1
    Its not going to work. Selenium Grid only works with webdriver commands. Any external script or code will not work over grid.
    – H.D.
    Apr 3, 2017 at 21:54
0

Java Robot class might help you, though it's also a good candidate to induce flakiness to your test suite. The class itself allows you to move the physical mouse around the screen (so using it on a server with no mouse attached might result in problems) and, of course, has no context to evaluate if the given coordinates are really matching the place you want it to be. Using it via the grid might be problematic, tbh, I have not yet had much experience with distributed environments but if you want to stay in Java I think it might be your only solution since Selenium lives inside your Browsers sandbox and can't (and honestly, shouldn't) act outside of it.

Here is the documentation for javas robot, though like I said, try to keep it as a last solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.